Summary and diagnostic information for evaluating within-fixed-effect variation.
Sumhdfe is a Stata package that produces summary and diagnostic information of linear fixed effect models.
You can use sumhdfe
to:
Sumhdfe is currently in beta version and we welcome comments and suggestions in the issue
tab!
For a discussion on the issues that sumhdfe
addresses, see deHaan (2021).
Similarly, if you find these diagnostics to be useful, please cite:
deHaan, Ed. (2021). Using and Interpreting Fixed Effects Models.
Available at SSRN: https://ssrn.com/abstract=3699777.
Sumhdfe
is an extension to reghdfe
and requires version 6+ of reghdfe
and ftools
to work. In order to generate .rtf files you also need to have rtfutil
installed.
To install sumhdfe
and its dependencies follow the steps below:
* Uninstall any old versions of ftools, reghdfe, sumhdfe
cap ado uninstall ftools
cap ado uninstall reghdfe
cap ado uninstall sumhdfe
* Install the most recent version of ftools, reghdfe, and sumhdfe
net install ftools, from("https://raw.githubusercontent.com/sergiocorreia/ftools/master/src/")
net install reghdfe, from("https://raw.githubusercontent.com/sergiocorreia/reghdfe/master/src/")
net install sumhdfe, from("https://raw.githubusercontent.com/ed-dehaan/sumhdfe/master/src/")
* To generate rtf files you also need to install rtfutil
ssc install rtfutil
Note: sumhdfe
does not work with reghdfe
version 5, which is the version that is installed by when running ssc install reghdfe
.
Make sure to use the commands above to install reghdfe
version 6.
Sumhdfe
can be used in one of two ways:
reghdfe
Post-estimation version
First run reghdfe
and then run sumhdfe
. A simple example is show below, see the Stata help file for additional examples.
use "https://raw.githubusercontent.com/ed-dehaan/sumhdfe/master/sumhdfe_demo_data.dta", clear
reghdfe y x1 x2 , a(firm year)
sumhdfe
Standalone version
Run sumhdfe
directly.
use "https://raw.githubusercontent.com/ed-dehaan/sumhdfe/master/sumhdfe_demo_data.dta", clear
sumhdfe y x1 x2 , a(firm year)
The sumhdfe
command will provide four panels by default:
Additionally, sumhdfe
can provide:
Summary statistics for the sample used in reghdfe
.
Example:
Notes:
estat summarize
reghdfe
outputpanels(str)
option, this panel can be selected using the sum
accronym: panels(sum)
Summary statistics for the fixed effects themselves.
Example:
Notes:
reghdfe
output.panels(str)
option, this panel can be selected using the fe
accronym: panels(fe)
Panel C quantifies how often each variable is constant within a given fixed effect group (such as within a given firm). These observations can have unexpected effects on regression coefficients and, if numerous, should be carefully evaluated.
Example:
Notes:
panels(str)
option, this panel can be selected using the zero
accronym: panels(zero)
Panel D shows how much variation in each variable is lost (or absorbed) due to the fixed effects, in terms of both standard deviations and r-squared.
Example:
Notes:
panels(str)
option, this panel can be selected using the rss
accronym: panels(rss)
The histogram(#)
option tabulates the frequencies of observations within a fixed effect grouping.
Example:
For example, sumhdfe, histogram(1)
shows the frequencies of observations for the first fixed effect grouping listed within a(firm year)
, i.e., firm. You can also specify the fixed effect name; for example sumhdfe, histogram(year)
.
All panels can be exported to a publication ready RTF or Latex table. The RTF table can be used in Word or Excel (by copying the contents to an Excel sheet).
To export the tables:
sumhdfe
sumhdfe_export
command panels(a b c d)
“help sumhdfe_export
sumhdfe_export
will determine the output, use .rtf
or .tex
Example 1: RTF
reghdfe y x1 x2, a(firm year)
sumhdfe
sumhdfe_export using table.rtf, panels(a b c d)
You can open the .rtf
file using Word and you can copy the table to Excel as well.
Example 2: Tex
reghdfe y x1 x2, a(firm year)
sumhdfe
sumhdfe_export using table.tex, panels(a b c d) standalone
You can render the .tex
file using your prefered LaTeX editor (e.g., Overleaf).
For additional examples and additional options, see the stata help file with help sumhdfe
and help sumhdfe_export
use "https://raw.githubusercontent.com/ed-dehaan/sumhdfe/master/sumhdfe_demo_data.dta", clear
qui: reghdfe y x1 x2, a(firm year)
qui: reghdfe x1 if e(sample), a(firm year) resid
twoway (histogram x1, fcolor(green%75) lcolor(none)) (histogram _reghdfe_resid, ///
fcolor(navy%70) lcolor(none)), legend(on order(1 "x1" 2 "within-FE x1"))
If you have questions or experience problems please use the issues tab of this repository.
Known bugs: