Category Archives: Stata

Display full variable names in State Results window

In State, the default width for displaying variable names in the Results window is set to 12. Sometimes it can be frustrating not to see the full variable names. Consider the following results from the tabstat command: Ideally, we’d prefer … Continue reading

Posted in Stata | Leave a comment

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

A test on Stata running speed on MacBook Pro (M1 Pro chip) and old Macs

I ran a test on Stata running speed on my newest MacBook Pro (14-inch, 2021) and two old Macs—iMac (27-inch, 2019) and MacBook Pro (16-inch, 2019). Technical specifications: MacBook Pro (14-inch, 2021): CPU Apple M1 Pro (10-core), memory 16G, SSD … Continue reading

Posted in Stata | 6 Comments

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 | 9 Comments

Stata command to perform Chow test

A Chow test is simply a test of whether the coefficients estimated over one group of the data are equal to the coefficients estimated over another. I find two useful articles from Stata’s official website: Can you explain Chow tests? … Continue reading

Posted in Stata | 6 Comments

Stata command to lowercase all variable names or the values of all string variables

Stata is a case-sensitive application, which can sometimes cause trouble. Therefore, we might want to convert all variable names or the values of all string variables to lowercase before further data processing. This post gives a quick method to do … Continue reading

Posted in Stata | 2 Comments

Stata command to order tabulation result with only top values shown

tabulate varname command is handy in Stata, but sometimes it returns a too long result, if varname contains too many unique values. The third-party command, groups, will solve the problem by showing top values only. Please use ssc install groups … Continue reading

Posted in Stata | Leave a comment

Empower “and” and “or” in IF statement in Stata

Stata is a little bit awkward when using and and or in if statement, compared to SAS. For example: In SAS, we can write if 2001 <= fyear <= 2010. But in Stata, we usually write: if fyear >= 2001 … Continue reading

Posted in Stata | 1 Comment