Categories
 Data (7)
 Learning Resources (8)
 Python (7)
 SAS (11)
 Stata (14)
 Uncategorized (2)

Recent Posts
 The calculation of average credit rating using ratings from three rating agencies
 Stata commands to test equality of mean and median
 Handy Stata command to display combined Pearson and Spearman correlation matrix
 Stata command to convert string GVKEY to numerical GVKEY or vice versa
 Stata command to calculate the area under ROC curve
Recent Comments
 Joe on Calculate idiosyncratic stock return volatility
 Sabrina on About Me
 Jixun on Calculate market value of equity: use CRSP or Compustat?
 Hui on A loop of crosssectional regressions for calculating abnormal accruals in Stata
 Shuo Wang on The calculation of average credit rating using ratings from three rating agencies
Archives
Meta
Category Archives: Stata
Stata commands to test equality of mean and median
UCLA IDRE has posted an article (link) that may provide a bit more explanation. UCLA IDRE is a great resource for learning statistical analysis. A big thank you to them.
Posted in Stata
Leave a comment
Handy Stata command to display combined Pearson and Spearman correlation matrix
Oftentimes we would like to display Pearson correlations below the diagonal and Spearman correlations above the diagonal. Two builtin commands, pwcorr and spearman, can do the job. However, we have to manually combine Stata output tables when producing the correlation table … Continue reading
Posted in Stata
Leave a comment
Stata command to convert string GVKEY to numerical GVKEY or vice versa
The default type of GVEKY in Compustat is string. Sometimes, we need it to be a numerical type in Stata (e.g., when we want to use the super handy command tsset). The command to convert string GVKEY to numerical GVEKY … Continue reading
Stata command to calculate the area under ROC curve
If we want to evaluate the predictive ability of a logit or probit model, Kim and Skinner (2012, JAE, Measuring securities litigation risk) suggest that A better way of comparing the predictive ability of different models is to use the Receiver … Continue reading
Posted in Stata
Leave a comment
Stata commands to calculate skewness
Suppose we are going to calculate the skewness of 12 monthly returns. The 12 returns may be stored in a row (Figure 1) or in a column (Figure 2). This post discusses how to calculate the skewness in these two … Continue reading
Posted in Stata
Leave a comment
Commonly used Stata commands to deal with potential outliers
In accounting archival research, we often take it for granted that we must do something to deal with potential outliers before we run a regression. The commonly used methods are: truncate, winsorize, studentized residuals, and Cook’s distance. I discuss in … Continue reading
Posted in Stata
2 Comments
Sample code for “outreg” command in Stata
outreg is very powerful and timesaving command in Stata. The following code generates a readyforuse results table:
1 2 3 4 5 
outreg, stats(b p) sdec(3) /// summstat(r2_a \ N) summdec(3,0) summtitles("Adjusted R2" \ "N") /// starlevels(10 5 1) starloc(1) /// ctitles("", "Heading" \ "", "Subheading") /// keep(_cons x1 x2 x3 x4) 
Please change x1, x2, x3 and x4 to variables that you want to report.
Posted in Stata
Leave a comment
A loop of crosssectional regressions for calculating abnormal accruals in Stata
I write a loop of crosssectional regressions for calculating abnormal accruals. This program can be easily modified and replaced with Jones, modified Jones, or Dechow and Dichev model. I add detailed comments in the program to help you prepare the input … Continue reading
Posted in Stata
7 Comments
Rollingwindow computation in SAS and Stata
SASers often find proc expand plus transformout very useful for rollingwindow (or movingwindow) computation. Stataers may wonder if there is a counter party in Stata. The answer is “yes”. The command in Stata is rolling. See the manual below: http://www.stata.com/manuals13/tsrolling.pdf The … Continue reading
Posted in Learning Resources, SAS, Stata
Leave a comment
Regression with a large dummyvariable set (e.g., firm and year fixed effects) in Stata
I run a regression in Stata with a Compustat dataset that contains fyear and gvkey. I want to add firm and year fixed effects, so I type the following command: regress DV IV i.fyear i.gvkey But Stata returns the error … Continue reading
Posted in Stata
Leave a comment