Documente Academic
Documente Profesional
Documente Cultură
By declaring data type, you enable Stata to apply data munging and analysis functions specific to certain data types
with Stata 14.1 Cheat Sheet TIME SERIES webuse sunspot, clear PANEL / LONGITUDINAL webuse nlswork, clear
For more info see Stata’s reference manual (stata.com) tsset time, yearly xtset id year
Results are stored as either r -class or e -class. See Programming Cheat Sheet declare sunspot data to be yearly time series declare national longitudinal data to be a panel
tsreport xtdescribe
Summarize Data Examples use auto.dta (sysuse auto, clear)
unless otherwise noted r
report time series aspects of a dataset report panel aspects of a dataset xtline plot
r wage relative to inflation
univar price mpg, boxplot ssc install univar generate lag_spot = L1.spot xtsum hours 4
id 1 id 2
calculate univariate summary, with box-and-whiskers plot create a new variable of annual lags of sun spots tsline plot summarize hours worked, decomposing 2
return stem-and-leaf display of mpg plot time series of sunspots 100 within components 4
id 3 id 4
Statistical Tests 1 Estimate Models stores results as e -class 2 Diagnostics not appropriate with robust standard errors
tabulate foreign rep78, chi2 exact expected regress price mpg weight, robust estat hettest test for heteroskedasticity
tabulate foreign and repair record and return chi2 estimate ordinary least squares (OLS) model r ovtest test for omitted variable bias
and Fisher’s exact statistic alongside the expected values on mpg weight and foreign, apply robust standard errors vif report variance inflation factor
ttest mpg, by(foreign) regress price mpg weight if foreign == 0, cluster(rep78) dfbeta(length) Type help regress postestimation plots
estimate t test on equality of means for mpg by foreign regress price only on domestic cars, cluster standard errors calculate measure of influence for additional diagnostic plots
rreg price mpg weight, genwt(reg_wt) rvfplot, yline(0) avplots
r prtest foreign == 0.5
price
price
estimate robust regression to eliminate outliers plot residuals plot all partial-
Residuals
mpg rep78
one-sample test of proportions probit foreign turn price, vce(robust) against fitted regression leverage
ADDITIONAL MODELS
price
price
ksmirnov mpg, by(foreign) exact estimate probit regression with pca built-in Stata principal components analysis
Fitted values values headroom weight plots in one graph
Kolmogorov-Smirnov equality-of-distributions test robust standard errors
3 Postestimation
command
factor factor analysis
commands that use a fitted model
ranksum mpg, by(foreign) exact logit foreign headroom mpg, or poisson • nbreg count outcomes
equality tests on unmatched data (independent samples) estimate logistic regression and tobit censored data
regress price headroom length Used in all postestimation examples
ivregress ivreg2 instrumental variables
report odds ratios
anova systolic drug webuse systolic, clear bootstrap, reps(100): regress mpg /* rddiff sscuser-written difference-in-difference display _b[length] display _se[length]
analysis of variance and covariance */ weight gear foreign
install ivreg2 regression discontinuity
return coefficient estimate or standard error for mpg
e pwmean mpg, over(rep78) pveffects mcompare(tukey)
xtabond xtabond2 dynamic panel estimator from most recent regression model
estimate regression with bootstrapping psmatch2
jackknife r(mean), double: sum mpg synth
propensity score matching
margins, dydx(length) returns e-class information when post option is used
estimate pairwise comparisons of means with equal synthetic control analysis
variances include multiple comparison adjustment jackknife standard error of sample mean oaxaca Blinder-Oaxaca decomposition r
return the estimated marginal effect for mpg
margins, eyex(length)
Estimation with Categorical & Factor Variables more details at http://www.stata.com/manuals14/u25.pdf return the estimated elasticity for price
CONTINUOUS VARIABLES OPERATOR DESCRIPTION EXAMPLE predict yhat if e(sample)
measure something i. specify indicators regress price i.rep78 specify rep78 variable to be an indicator variable create predictions for sample on which model was fit
ib. specify base indicator regress price ib(3).rep78 set the third category of rep78 to be the base category predict double resid, residuals
CATEGORICAL VARIABLES fvset command to change base fvset base frequent rep78 set the base to most frequently occurring category for rep78
identify a group to which calculate residuals based on last fit model
c. treat variable as continuous regress price i.foreign#c.mpg i.foreign treat mpg as a continuous variable and
an observations belongs specify an interaction between foreign and mpg test mpg = 0
r test linear hypotheses that mpg estimate equals zero
o. omit a variable or indicator regress price io(2).rep78 set rep78 as an indicator; omit observations with rep78 == 2
INDICATOR VARIABLES
denote whether # specify interactions regress price mpg c.mpg#c.mpg create a squared mpg term to be used in regression
T F lincom headroom - length
something is true or false ## specify factorial interactions regress price c.mpg##c.mpg create all possible interactions with mpg (mpg and mpg2)
test linear combination of estimates (headroom = length)
Tim Essam (tessam@usaid.gov) • Laura Hughes (lhughes@usaid.gov) inspired by RStudio’s awesome Cheat Sheets (rstudio.com/resources/cheatsheets) geocenter.github.io/StataTraining updated March 2016
Disclaimer: we are not affiliated with Stata. But we like it. CC BY NC