Tag Archives: Stata

How to prevent the “log file already open” error when working with log files in Stata

Sometimes we use the log using filename, replace command at the beginning of a Do file to open a log file and record everything displayed in the Results window. However, if an error interrupts the previous execution of the Do … Continue reading

Posted in Stata | Tagged | Leave a comment

Stata command to draw a graph showing the average of a variable by group

Suppose we have the following dataset that provides the life expectancy (lexp) of each country in each region: We can draw a bar graph to show the average (or other statistics) life expectancy of each region using two different methods: … Continue reading

Posted in Stata | Tagged | 2 Comments

Stata command to rename groups of variables

Swap variable names: rename (v1 v2) (v2 v1) Lowercase (or uppercase, or propercase) groups of variable names: rename V1 V2, lower or rename *, lower Add suffix _old to variables v1, v2, … for one or more digits: rename v# … Continue reading

Posted in Stata | Tagged | Leave a comment

Stata command to perform propensity score matching (PSM)

Most propensity score matching (PSM) examples typically use cross-sectional data rather than panel data. However, in accounting research, panel data (observations with two subscripts i and t, e.g., firm-years) are often used in a difference-in-differences (DID) research design. This involves … Continue reading

Posted in Stata | Tagged | 10 Comments