Profile picture
Seth Gershenson @SethGershenson
, 35 tweets, 14 min read Read on Twitter
This tweet was more popular that I expected. So here's a thread of other user-written @stata commands that I find useful 1/
But first, why did u like the tweet? Did it make u feel... 2/
Let's start w commands that help present/describe data/results. This is super important and w/o it, all the fancy methods in the world won't matter. 3/
outreg2: puts regression output in nice, journal-quality tables. Can export to excel, word, or LaTex. Lots of labeling and output and format options. you run the command immediately after the regression. repec.org/bocode/o/outre… 4/
outreg2 example:

reg y x
outreg2 using my_output_file, ctitle(title describing reg y x) excel dec(3) e(all)

*excel says I want table in excel file; dec(3) is number of decimal places; e(all) is the regression statistics I want in table (can delete some later). 5/
coefplot: plot regression point estimates & confidence intervals. useful for event study showing parallel trends, show robustness of one point estimate to different modeling choices, or compare effect sixes of different x. within or between regressions. repec.sowi.unibe.ch/stata/coefplot… 6/
coefplot example: (run after regression(s); if many regs, store estimates)

reg y x z
estimates store b1

reg y x w
estimates store b2

coefplot b1 b2, vertical keep(x)

*keep(.) selects variables to plot; vertical sets axis. 7/
binscatter by @michaelstepner: plots mean of y for different bins of x. super helpful for visualizing correlations, esp in big sample when plotting raw data yields a blotch of ink. also for plotting RD reduced forms & event studies. michaelstepner.com/binscatter/ 8/
moving to general regression stuff, ivreg2 & xtivreg2 are useful to reporting all sort of iv diagnostics, but ALSO can compute multi-way clustered standard errors, for OLS and 2SLS (x are their own instruments in OLS). repec.org/bocode/i/ivreg… 9/
reghdfe: estimates multi-way fixed effects models. also allows for multi-way clustering. I think this is the best option available, though this is an active area of research scorreia.com/software/reghd… 10/
gllamm: is truly amazing and I could never list all its features. estimate finite mixture models, random coefficient models, mixed models, and Heckman-Singer discrete mass point models. gllamm.org 11/
cmp: estimate mixed-process models. vry flexible. many reasons you might want this, but I used it in case of IV setup w limited dep. variables. Think an ordinal outcome w/ binary endog variable, or "tri probit" w/ 2 endog vars. fmwww.bc.edu/EC-C/S2016/882… 12/
unique x tells you how many unique values of x are in the data.

for example, unique studentid will tell you how many unique student ids are in your dataset. super helpful for making sense of messy data as you clean and organize. ideas.repec.org/c/boc/bocode/s… 13/
moving on to some more specialized commands now. first, here are two quantile regression commands 14/
ivqreg implements the quantile-IV estimator proposed by Chernozhukov and Hansen. Written by @MSUEconomics grad Do Wan Kwak. msu.edu/~kwakdo/ivqreg… 15/
qregpd implements a fixed effect quantile-regression estimator, proposed & written by @RANDCorporation 's David Powell. The paper very nicely articulates the issues w FE in quantile regs. works.bepress.com/david_powell/1/ 16/
Next is RD. Here, Matias Cattaneo of @umichMES et al. provide a huge service to profession by coding up, and clearly explaining, all of their RD estimators. rdrobust is a godsend. rddensity implemetns a nonparametric manipulation test. sites.google.com/site/matiasdca… 17/
synth implements the sythentic control method of Abadie et al. See papers.ssrn.com/sol3/papers.cf… for an accessible intro to SCM. There is an R version available too: web.stanford.edu/~jhain/synthpa… 18/
leebounds implements Lee (2009) bounds. provides bounds for causal effect of treatment in RCT when outcome is not observed for for everyone, for reason related to treatment. nice @Stata journal article here: stata-journal.com/article.html?a… 19/
Coming back to IV land, margte estimates marginal treatment effects. stata-journal.com/article.html?a… 20/
And this ReStat article describes how to test monotonicity (in the LATE sense) using the intersection bounds command of Chernozhoukov et al. stata-journal.com/article.html?a… mitpressjournals.org/doi/abs/10.116… 21/
I missed this in the earlier "general" part, but clustse performs the wild-cluster bootstrap for clustering w small-N of clusters. ideas.repec.org/c/boc/bocode/s… 22/
cem performs coarsened exact matching, by @kinggary et al. HAve not used this one yet but look forward to experimenting with it in my causal inference class this summer. gking.harvard.edu/files/gking/fi… 23/
Winding down now. This is not exhaustive and might be outdated in some places. but I hope it's helpful. Please add on to list - I am sure there's lots of cool stuff I don;t know about. 24/
Keep in mind these are all written by regular folks doing a big service to science & much of our work depends on it - so cite appropriately and be kind/gracious when asking authors questions about code. 25/
Finally @AustnNchols & @mike_bader have already told me estout & esttab dominate outreg2 for making tables. they're probably right. but I used outreg2 in grad school and old habits die hard. repec.org/bocode/e/estou… 26/
And summary stat tables? I use estpost, part of estout:

estpost tabstat x, statistics(mean sd) columns(statistics) listwise
esttab using mytable.csv, main(mean) aux(sd) b(2) nostar unstack

* @athay20m suggests sutex for Tex. I will check it out fmwww.bc.edu/RePEc/bocode/s… 27/27
PS - I forgot craggit, which implements Cragg's Hurdle model. Bonus points for being super fun to say. craggit. ageconsearch.umn.edu/bitstream/1430…
PPS should also add elasticregress, which implements ML lasso, ridge, and elastic net regressions. HT @causalinf : ideas.repec.org/c/boc/bocode/s… This is really the end. 29/29
one last quantile regression thing: grqreg will plot the coefficients and confidence intervals for each quantile. really this is how quantile estimates should be reported. stata.com/statalist/arch…
Forgot that @stata makes MAPS (ht @paulgp ). an @AU_SPA PhD student used spmap last semester to show geography of racially motivated killings in S. Africa: stata.com/support/faqs/g… ALSO SEE maptile (by @michaelstepner) : michaelstepner.com/maptile/
psacalc: @ProfEmilyOster 's "sorting on observables" procedure for constructing bounds. another paper I look forward to digging in to in my causal inference class this summer. ideas.repec.org/c/boc/bocode/s… nber.org/papers/w19054
inteff, I forgot inteff to compute avg partial interaction effects in probit and logit. though margins made this somewhat redundant. stata-journal.com/article.html?a…
I just learned that typing "adoupdate" will update all of your userwritten commands. my ivreg2 was out of date, which is why it wouldn't allow a factor variable. you might need to exit and re-open @Stata after the udpate.
I forgot to include the excellent egenmore. egen x = nvals(z) will create x, the number of unique values of z. AND it allows by!! econpapers.repec.org/software/bocbo… . PS are we having fun yet @clconaway? I'm having fun. It is friday afternoon after all.
Missing some Tweet in this thread?
You can try to force a refresh.

Like this thread? Get email updates or save it to PDF!

Subscribe to Seth Gershenson
Profile picture

Get real-time email alerts when new unrolls are available from this author!

This content may be removed anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just three indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member and get exclusive features!

Premium member ($3.00/month or $30.00/year)

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!