Home

Awesome

IVREGHDFE: reghdfe + ivreg2 (adds instrumental variable and additional robust SE estimators to reghdfe)

GitHub release (latest by date) GitHub Release Date GitHub commits since latest release (by date) StataMin DOI

This package integrates reghdfe into ivreg2, through an absorb() option. This allows IV/2SLS regressions with multiple levels of fixed effects.

Recent updates

Comparison with other commands

As seen in the table below, ivreghdfe is recommended if you want to run IV/LIML/GMM2S regressions with fixed effects, or run OLS regressions with advanced standard errors (HAC, Kiefer, etc.)

Commandregressaregreghdfeivreg2ivreghdfe
Models:OLSOLSOLSOLS, IV, LIML, GMM2S, CUEOLS, IV, LIML, GMM2S (not CUE!)
Fixed effects?-One-wayMulti-way-Multi-way
Cluster SE?One-wayOne-wayMulti-wayTwo-wayTwo-way
Additional SEs:---AC, HAC, Kiefer, Driscol-Kraay, etc.AC, HAC, Kiefer, Driscol-Kraay, etc.
(Speed) Time without FEs:1x-2x3.7x4.3x
(Speed) Time with one FE:-6.3x2.1x-4.6x

(Benchmark run on Stata 14-MP (4 cores), with a dataset of 4 regressors, 10mm obs., 100 clusters and 10,000 FEs)

Installation

ivreghdfe requires three packages: ivreg2, reghdfe (version 5.x) and ftools. Run the lines below to install everything you might possibly need:

* Install ftools (remove program if it existed previously)
cap ado uninstall ftools
net install ftools, from("https://raw.githubusercontent.com/sergiocorreia/ftools/master/src/")

* Install reghdfe
cap ado uninstall reghdfe
net install reghdfe, from("https://raw.githubusercontent.com/sergiocorreia/reghdfe/master/src/")

* Install ivreg2, the core package
cap ado uninstall ivreg2
ssc install ivreg2

* Finally, install this package
cap ado uninstall ivreghdfe
net install ivreghdfe, from(https://raw.githubusercontent.com/sergiocorreia/ivreghdfe/master/src/)

Advice

This code just modifies ivreg2 adding an absorb() option that uses reghdfes Mata functions (see this link for the line-by-line differences). When used, absorb() will also activate the small, noconstant and nopartialsmall options of ivreg2 (basically to force small sample adjustments, which are required as we might have a substantial number of fixed effects).

You can also use all other reghdfe options as normal options of ivreghdfe (e.g. tolerance, choice of transform, etc.):

sysuse auto, clear
ivreghdfe price weight (length=gear), absorb(turn trunk) tol(1e-6) accel(sd)

This is gives the same result as using the old version of reghdfe (but slower):

reghdfe price weight (length=gear), absorb(turn trunk) tol(1e-6) accel(sd) version(3)

Residuals

To save residuals, do this:

sysuse auto
ivreghdfe price weight, absorb(trunk) resid(myresidname)

You can also use the other predict options of reghdfe, such as d:

predict d, d