### Install REGHDFE Development Version Source: https://scorreia.com/software/reghdfe/install.html Installs the latest development version of reghdfe and its dependencies from GitHub. Ensure ftools and parallel are installed if needed. This method is recommended for accessing recent improvements. ```stata * 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 6.x cap ado uninstall reghdfe net install reghdfe, from("https://raw.githubusercontent.com/sergiocorreia/reghdfe/master/src/") * Install parallel, if using the parallel() option; don't install from SSC cap ado uninstall parallel net install parallel, from(https://raw.githubusercontent.com/gvegayon/parallel/stable/) replace mata mata mlib index ``` -------------------------------- ### Install IVREGHDFE for IV/GMM Regressions Source: https://scorreia.com/software/reghdfe/install.html Installs ivreghdfe, which is required for running IV/GMM regressions. It also installs ivreg2 as a core dependency. Use this command after installing the main reghdfe package. ```stata cap ado uninstall ivreghdfe cap ssc install ivreg2 // Install ivreg2, the core package net install ivreghdfe, from(https://raw.githubusercontent.com/sergiocorreia/ivreghdfe/master/src/) ``` -------------------------------- ### Manual Installation of REGHDFE Packages Source: https://scorreia.com/software/reghdfe/install.html Provides commands for manual installation of reghdfe, ftools, and ivreghdfe from local directories. This is useful for firewalled servers. Ensure the zip files are downloaded and extracted to the specified paths. ```stata cap ado uninstall ftools cap ado uninstall reghdfe cap ado uninstall ivreghdfe net install ftools, from(c:\git\ftools) net install reghdfe, from(c:\git\reghdfe) net install ivreghdfe, from(c:\git\ivreghdfe) ``` -------------------------------- ### Install REGHDFE Stable Version Source: https://scorreia.com/software/reghdfe/install.html Use this command to install the latest stable release of reghdfe from Stata's Statistical Software Components (SSC) archive. Requires Stata 13.1 or newer. ```stata ssc install reghdfe ``` -------------------------------- ### Fixed Effect Nested Within Cluster Example Source: https://scorreia.com/software/reghdfe/faq.html Demonstrates the 'fixed effect nested within cluster' scenario where a fixed effect variable is also used for clustering. The output shows a message indicating that the fixed effect is treated as redundant for DoF computation. ```stata . sysuse auto (1978 Automobile Data) `. reghdfe price weight length, absorb(turn trunk) vce(cluster turn)` (output omitted) Absorbed degrees of freedom: ---------------------------------------------------------------+ Absorbed FE | Num. Coefs. = Categories - Redundant | -------------+-------------------------------------------------| turn | 0 13 13 * | trunk | 12 13 1 | ---------------------------------------------------------------+ * = fixed effect nested within cluster; treated as redundant for DoF computation ``` -------------------------------- ### Clear Cached Regression Transformations Source: https://scorreia.com/software/reghdfe/faq.html Use the cache(clear) option to remove all saved transformations from the cache. This is useful to free up memory or start fresh. ```stata . reghdfe, cache(clear) ``` -------------------------------- ### Basic Syntax Comparison Source: https://scorreia.com/software/reghdfe/quickstart.html Compares the basic syntax of `areg` with `reghdfe` for absorbing fixed effects. ```stata . areg depvar indepvars, absorb(absvar) Becomes: . reghdfe depvar indepvars, absorb(absvar1 absvar2 …) ``` ```stata . reghdfe depvar indepvars (endogvars=iv_vars), absorb(absvars) ``` ```stata . reghdfe depvar indepvars , absorb(absvars) vce(robust) ``` ```stata . reghdfe depvar indepvars , absorb(absvars) vce(cluster clustervars) ``` -------------------------------- ### Manage Memory with pool() Option Source: https://scorreia.com/software/reghdfe/faq.html Use the pool(#) option with a smaller value to reduce memory usage and avoid out-of-memory errors. The default is 10. ```stata . reghdfe y x1 x2 , absorb(country#year) pool(5) ``` -------------------------------- ### Use Cached Regression Transformations Source: https://scorreia.com/software/reghdfe/faq.html Use the cache(use) option to load previously saved transformations. This speeds up regressions when the absorbed fixed effects are the same as a previous regression. ```stata . reghdfe price length, absorb(turn trunk) cache(use) HDFE Linear regression Number of obs = 65 Absorbing 2 HDFE groups F( 1, 39) = 4.54 Prob > F = 0.0394 R-squared = 0.4598 Adj R-squared = 0.1136 Within R-sq. = 0.1043 Root MSE = 2727.2009 ------------------------------------------------------------------------------ price | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- length | 114.9727 53.95093 2.13 0.039 5.846653 224.0988 ------------------------------------------------------------------------------ Absorbed degrees of freedom: ---------------------------------------------------------------+ Absorbed FE | Num. Coefs. = Categories - Redundant | -------------+-------------------------------------------------| turn | 13 13 0 | trunk | 12 13 1 | ---------------------------------------------------------------+ ``` ```stata . reghdfe price weight, absorb(turn trunk) cache(use) HDFE Linear regression Number of obs = 65 Absorbing 2 HDFE groups F( 1, 39) = 25.39 Prob > F = 0.0000 R-squared = 0.6347 Adj R-squared = 0.4005 Within R-sq. = 0.3943 Root MSE = 2242.7172 ------------------------------------------------------------------------------ price | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- weight | 5.055336 1.003362 5.04 0.000 3.025846 7.084826 ------------------------------------------------------------------------------ Absorbed degrees of freedom: ---------------------------------------------------------------+ Absorbed FE | Num. Coefs. = Categories - Redundant | -------------+-------------------------------------------------| turn | 13 13 0 | trunk | 12 13 1 | ---------------------------------------------------------------+ ``` -------------------------------- ### Generate formatted regression tables with estfe and esttab Source: https://scorreia.com/software/reghdfe/faq.html Use estfe to prepare fixed effect labels for esttab, ensuring clean output for models with multiple fixed effects. ```stata * Setup sysuse auto * Run and store regressions reghdfe price weight length, a(turn) keepsing estimates store model1 reghdfe price weight length, a(turn trunk) keepsing estimates store model2 reghdfe price weight length, a(turn foreign) keepsing estimates store model2 * Prepare estimates for -estout- estfe . model*, labels(turn "Turn FE" turn#trunk "Turn-Trunk FE") return list * Run estout/esttab esttab . model* , indicate("Length Controls=length" `r(indicate_fe)') * Return stored estimates to their previous state estfe . model*, restore ``` -------------------------------- ### Cache Regression Transformations Source: https://scorreia.com/software/reghdfe/faq.html Use the cache(save) option to compute and save transformations for later use. This avoids recomputing them for subsequent regressions with the same absorbed fixed effects. ```stata . sysuse auto (1978 Automobile Data) . reghdfe price weight length, absorb(turn trunk) cache(save) (dropped 9 singleton observations) (converged in 12 iterations) ``` -------------------------------- ### Multi-way Clustering Without Fixed Effects Source: https://scorreia.com/software/reghdfe/faq.html Shows how to perform regression with multi-way clustering using REGHDFE without specifying any fixed effects. This is achieved by omitting the `absorb()` option and providing multiple cluster variables to `vce(cluster ...)`. The output includes robust standard errors adjusted for the specified clusters. ```stata . sysuse auto (1978 Automobile Data) `. reghdfe price weight length, vce(cluster turn trunk)` (converged in 1 iterations) HDFE Linear regression Number of obs = 74 Absorbing 1 HDFE group F( 2, 17) = 34.60 Statistics robust to heteroskedasticity Prob > F = 0.0000 R-squared = 0.3476 Adj R-squared = 0.3292 Number of clusters (turn) = 18 Within R-sq. = 0.3476 Number of clusters (trunk) = 18 Root MSE = 2415.7351 (Std. Err. adjusted for 18 clusters in turn trunk) ------------------------------------------------------------------------------ | Robust price | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- weight | 4.699065 2.650909 1.77 0.094 -.8938651 10.29199 length | -97.96031 91.6812 -10.7 0.300 -291.3907 95.4701 ------------------------------------------------------------------------------ ``` -------------------------------- ### Estimate IV Regression with reghdfe Source: https://scorreia.com/software/reghdfe/quickstart.html Use this command to estimate an instrumental variables regression with absorbed fixed effects. The syntax specifies the dependent variable, endogenous regressors in parentheses, and exogenous regressors. Absorbed fixed effects are specified using the `absorb()` option. ```stata . reghdfe price weight (length = gear), absorb(turn trunk) ``` -------------------------------- ### Estimate OLS with Fixed Effects Source: https://scorreia.com/software/reghdfe/quickstart.html Estimates an OLS regression with two levels of fixed effects using `reghdfe`. Ensure data is loaded and necessary variables are present. ```stata . sysuse auto (1978 Automobile Data) . reghdfe price weight length, absorb(turn trunk) (dropped 9 singleton observations) (converged in 12 iterations) HDFE Linear regression Number of obs = 65 Absorbing 2 HDFE groups F( 2, 38) = 12.85 Prob > F = 0.0001 R-squared = 0.6403 Adj R-squared = 0.3942 Within R-sq. = 0.4035 Root MSE = 2254.6288 ------------------------------------------------------------------------------ price | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- weight | 5.688144 1.302818 4.37 0.000 3.050727 8.325561 length | -44.21191 57.60797 -0.77 0.448 -160.8332 72.40933 -------------+---------------------------------------------------------------- Absorbed | F(24, 38) = 1.548 0.110 (Joint test) ------------------------------------------------------------------------------ Absorbed degrees of freedom: ---------------------------------------------------------------+ Absorbed FE | Num. Coefs. = Categories - Redundant | -------------+-------------------------------------------------| turn | 13 13 0 | trunk | 12 13 1 | ---------------------------------------------------------------+ ``` -------------------------------- ### Estimate OLS with Two-Way Clustering Source: https://scorreia.com/software/reghdfe/quickstart.html Estimates an OLS regression with two-way clustering on fixed effects using `reghdfe`. This is useful for handling clustered errors. ```stata . reghdfe price weight length, absorb(turn trunk) vce(cluster turn trunk) (dropped 9 singleton observations) (converged in 12 iterations) HDFE Linear regression Number of obs = 65 Absorbing 2 HDFE groups F( 2, 12) = 16.59 Statistics robust to heteroskedasticity Prob > F = 0.0004 R-squared = 0.6403 Adj R-squared = 0.3778 Number of clusters (turn) = 13 Within R-sq. = 0.4035 Number of clusters (trunk) = 13 Root MSE = 2284.8937 (Std. Err. adjusted for 13 clusters in turn trunk) ------------------------------------------------------------------------------ | Robust price | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- weight | 5.688144 2.837967 2.00 0.068 -.4952552 11.87154 length | -44.21191 87.68177 -0.50 0.623 -235.2541 146.8302 ------------------------------------------------------------------------------ Absorbed degrees of freedom: ---------------------------------------------------------------+ Absorbed FE | Num. Coefs. = Categories - Redundant | -------------+-------------------------------------------------| turn | 0 13 13 * | trunk | 0 13 13 * | ---------------------------------------------------------------+ * = fixed effect nested within cluster; treated as redundant for DoF computation ``` -------------------------------- ### Absorb Combined Fixed Effects Source: https://scorreia.com/software/reghdfe/faq.html Absorb fixed effects from the combination of two variables using a single command. This is an alternative to creating a new grouped variable. ```stata . egen cou_year = group(country year) . reghdfe y x1 x2 , absorb(cou_year) ``` ```stata . reghdfe y x1 x2 , absorb(country#year) ``` -------------------------------- ### Absorb Combined Fixed Effects with Clustered SE Source: https://scorreia.com/software/reghdfe/faq.html Absorb fixed effects from the combination of two variables and cluster standard errors at the same level. ```stata . reghdfe y x1 x2 , absorb(country#year) vce(cluster country#year) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.