GithubHelp home page GithubHelp logo

smskim / ivreghdfe Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sergiocorreia/ivreghdfe

0.0 0.0 0.0 295 KB

Run IV/2SLS with many levels of fixed effects (i.e. ivreg2+reghdfe)

TeX 0.02% Stata 99.98%

ivreghdfe's Introduction

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

  • version 1.1.2 29Sep2022:
    • Fix bug #44; where cluster(...) worked but vce(cluster ...) was silently ignored
    • Fix bug #46; small correction to e(cmdline)
  • version 1.1.1 14dec2021:
    • Add experimental support for margins postestimation command.
  • version 1.1 26feb2021:
    • Update ivreg2 dependency from 4.1.10 9Feb2016 to 4.1.11 22Nov2019.
    • Update reghdfe dependency from 5.9.0 03jun2020 to 6.0.2 25feb2021
    • Before, reghdfe options had to be passed as suboptions of absorb(). Now they are passed directly as normal options
    • Note that some options are slightly different in reghdfe v6 (e.g. the exact technique used is set through the technique() option, following Stata convention).
    • Note that there might be a tiny difference in the SE estimates of ivreghdfe wrt those in reghdfe when both are used to run OLS instead of IV.
      • This happens if we have clustered standard errors, and the fixed effects are nested within the clusters.
      • Then, when computing the small sample adjustment q, reghdfe divides by (N-K-1) while ivreg2 (and thus ivreghdfe) divides by (N-K)
      • reghdfe does so to keep consistency with the small sample adjustment done by xtreg
      • For more details see comment in code ("minor adj. so we match xtreg when the absvar is nested within cluster")

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.)

Command regress areg reghdfe ivreg2 ivreghdfe
Models: OLS OLS OLS OLS, IV, LIML, GMM2S, CUE OLS, IV, LIML, GMM2S (not CUE!)
Fixed effects? - One-way Multi-way - Multi-way
Cluster SE? One-way One-way Multi-way Two-way Two-way
Additional SEs: - - - AC, HAC, Kiefer, Driscol-Kraay, etc. AC, HAC, Kiefer, Driscol-Kraay, etc.
(Speed) Time without FEs: 1x - 2x 3.7x 4.3x
(Speed) Time with one FE: - 6.3x 2.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

ivreghdfe's People

Contributors

sergiocorreia avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.