Archive

Posts Tagged ‘debugging’

What is wrong with my loop? Tips for solving errors in your loops


Introduction

When your analysis involves a repetitive task, you can write a loop in Stata to more efficiently perform this task. For example, you may want to fit a regression model separately for different industries or regions. In Stata, you can loop over values and items in a list to efficiently perform these types of tasks. However, if you come across an error when working with a loop, it may seem tricky to find the source of the error. Below, I show you some essential tools to help you solve errors in your loops: set trace, capture, noisily, and the if command. Read more…

A tip to debug your nl/nlsur function evaluator program

If you have a bug in your evaluator program, nl will produce, most probably, the following error:

your program returned 198
verify that your program is a function evaluator program
r(198);

The error indicates that your program cannot be evaluated.

The best way to spot any issues in your evaluator program is to run it interactively. You just need to define your sample (usually observations where none of the variables are missing), and a matrix with values for your parameters. Let me show you an example with nlces2. This is the code to fit the CES production function, from the documentation for the nl command: Read more…

Categories: Programming Tags: , , ,