### Setup for Examples Source: https://github.com/sergiocorreia/reghdfe/blob/master/docs/reghdfe.html This command loads the auto dataset, which is used in subsequent examples. ```stata . sysuse auto ``` -------------------------------- ### Manual Install reghdfe packages Source: https://github.com/sergiocorreia/reghdfe/blob/master/Readme.md Manual installation instructions for reghdfe, ftools, and ivreghdfe by downloading zip files and using net install. This is useful for firewalled servers. ```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 development hdfe Source: https://github.com/sergiocorreia/reghdfe/blob/master/docs/install.md Installs the development version of hdfe from GitHub. ```stata cap ado uninstall hdfe net from https://raw.githubusercontent.com/sergiocorreia/reghdfe/master/package/ net install hdfe ``` -------------------------------- ### Install REGHDFE and Dependencies Source: https://context7.com/sergiocorreia/reghdfe/llms.txt Install the required ftools dependency, the main reghdfe package, and the optional ivreghdfe package for instrumental variable support. ```stata * Install ftools (required dependency) cap ado uninstall ftools net install ftools, from("https://raw.githubusercontent.com/sergiocorreia/ftools/master/src/") ftools, compile mata: mata mlib index * Install reghdfe 6.x cap ado uninstall reghdfe net install reghdfe, from("https://raw.githubusercontent.com/sergiocorreia/reghdfe/master/src/") * Optional: Install ivreghdfe for instrumental variable regressions cap ado uninstall ivreghdfe cap ssc install ivreg2 net install ivreghdfe, from(https://raw.githubusercontent.com/sergiocorreia/ivreghdfe/master/src/) ``` -------------------------------- ### Install reghdfe manually Source: https://github.com/sergiocorreia/reghdfe/blob/master/docs/install.md Installs reghdfe from a local directory after downloading and extracting the zip file. ```stata cap ado uninstall reghdfe net from "C:\Temp\" net install reghdfe ``` -------------------------------- ### Install REGHDFE Package Source: https://github.com/sergiocorreia/reghdfe/blob/master/misc/old-Benchmarks/areg_xtreg.log.txt Installs the REGHDFE package from a specified URL. Ensure you have internet connectivity and Stata's net capabilities enabled. ```stata . net from https://raw.githubusercontent.com/sergiocorreia/reghdfe/updated_mata/package/ ---------------------------------------------------------------------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergiocorreia/reghdfe/updated_mata/package/ Sergio Correia, Duke University (sergio.correia@duke.edu) ---------------------------------------------------------------------------------------------------------------------------------------------- PACKAGES you could -net describe-: reghdfe REGHDFE - Linear regression with many high-dimensional fixed effects hdfe HDFE - Partial out variables with respect to a set of fixed effects ---------------------------------------------------------------------------------------------------------------------------------------------- . net install reghdfe checking reghdfe consistency and verifying not already installed... installation into c:\ado\plus\... installation complete. ``` -------------------------------- ### Install stable reghdfe Source: https://github.com/sergiocorreia/reghdfe/blob/master/docs/install.md Installs the stable version of reghdfe from the SSC repository. ```stata ssc install reghdfe ``` -------------------------------- ### Install ivreg2hdfe and ivreghdfe Source: https://github.com/sergiocorreia/reghdfe/blob/master/Readme.md Installs ivreg2, ivreg2hdfe, and ivreghdfe for IV/GMM regressions. This includes installing the core ivreg2 package from SSC and then ivreghdfe from GitHub. ```stata cap ado uninstall ivreg2hdfe 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/) ``` -------------------------------- ### Install ftools and reghdfe 6.x Source: https://github.com/sergiocorreia/reghdfe/blob/master/Readme.md Installs the latest version of ftools and reghdfe 6.x from GitHub. It first uninstalls any existing versions and then compiles ftools. ```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/") * compile ftools to prevent errors if you already had an older version installed: ftools, compile mata: mata mlib index * Install reghdfe 6.x cap ado uninstall reghdfe net install reghdfe, from("https://raw.githubusercontent.com/sergiocorreia/reghdfe/master/src/") ``` -------------------------------- ### Install stable hdfe Source: https://github.com/sergiocorreia/reghdfe/blob/master/docs/install.md Installs the stable version of hdfe from the SSC repository. ```stata ssc install hdfe ``` -------------------------------- ### Example reghdfe Usage Source: https://github.com/sergiocorreia/reghdfe/blob/master/docs/reghdfe.html Demonstrates basic usage of reghdfe with fixed effects absorption. ```stata _reghdfe price weight, absorb(turn trunk, savefe)_ ``` -------------------------------- ### Install stable/older reghdfe 5.x from SSC Source: https://github.com/sergiocorreia/reghdfe/blob/master/Readme.md Installs the stable, older version 5.x of reghdfe from SSC. It also includes steps to compile ftools. ```stata cap ado uninstall reghdfe ssc install reghdfe * compile ftools to prevent errors if you already had an older version installed: ftools, compile mata: mata mlib index ``` -------------------------------- ### Install development reghdfe Source: https://github.com/sergiocorreia/reghdfe/blob/master/docs/install.md Installs the latest development version of reghdfe directly from GitHub for Stata 13 or newer. ```stata cap ado uninstall reghdfe net from https://raw.githubusercontent.com/sergiocorreia/reghdfe/master/package/ net install reghdfe ``` -------------------------------- ### Using AvgE with Custom Name Source: https://github.com/sergiocorreia/reghdfe/blob/master/docs/reghdfe.html Similar to the previous example, but assigns a custom name 'AvgByOCC' to the average effect calculated for the 'occ' variable. ```stata . reghdfe ln_w grade age ttl_exp tenure not_smsa south , absorb(idcode year) avge(AvgByOCC=occ) ``` -------------------------------- ### Regression with Three Fixed Effects Source: https://github.com/sergiocorreia/reghdfe/blob/master/docs/reghdfe.html Extends the previous example by adding a third fixed effect, 'occ', to the absorption list. ```stata . reghdfe ln_w grade age ttl_exp tenure not_smsa south , absorb(idcode year occ) ``` -------------------------------- ### Run IV regression with stages and suboptions Source: https://github.com/sergiocorreia/reghdfe/blob/master/docs/reghdfe.html Demonstrates how to execute an instrumental variable regression while specifying auxiliary stages and passing suboptions to all stage regressions. ```stata reghdfe price (weight=length), absorb(turn) subopt(nocollin) stages(first, eform(exp(beta)) ) ``` -------------------------------- ### Convert SMCL to HTML Source: https://github.com/sergiocorreia/reghdfe/blob/master/publish.md Use the smcl2html script to generate the HTML version of the help file from the source .sthlp file. ```bash cd c:\git\parse-smcl smcl2html.py C:\git\reghdfe\src\reghdfe.sthlp --adopath=C:\Bin\Stata14\ado\base --view ``` -------------------------------- ### Implement a counter using asarray Source: https://github.com/sergiocorreia/reghdfe/blob/master/docs/dicts_in_stata.md Initialize a dictionary with a default value of 0 to track occurrences of keys. ```mata // create counter counter = asarray_create() asarray_notfound(counter, 0) // increase counter name = "John" asarray(counter, name, asarray(counter, name) + 1) ``` -------------------------------- ### Set up Panel Data Source: https://github.com/sergiocorreia/reghdfe/blob/master/misc/old-Benchmarks/areg_xtreg.log.txt Sets the data as panel data using `xtset`, specifying the panel variable (`id`) and time variable (`t`). This is a prerequisite for panel data analysis commands. ```stata . xtset id t panel variable: id (strongly balanced) time variable: t, 1 to 1000 delta: 1 unit ``` -------------------------------- ### Add YAML Front Matter Source: https://github.com/sergiocorreia/reghdfe/blob/master/publish.md Include this header at the top of the generated HTML file to ensure correct layout and menu integration. ```yaml --- title: Help File for REHGDFE.ADO layout: page sub-menu: reghdfe is-help: true --- ``` -------------------------------- ### Estimate Multiple Heterogeneous Slopes Source: https://context7.com/sergiocorreia/reghdfe/llms.txt Specify multiple heterogeneous slopes by interacting a categorical variable with multiple continuous variables using `##c.(var1 var2 ...)`. For example, `absorb(idcode##c.(age ttl_exp tenure))`. ```stata reghdfe ln_w grade, absorb(idcode##c.(age ttl_exp tenure)) ``` -------------------------------- ### Basic Usage of reghdfe Source: https://github.com/sergiocorreia/reghdfe/blob/master/docs/reghdfe.html Demonstrates the fundamental use of the reghdfe command with a single fixed effect. ```APIDOC ## POST /reghdfe ### Description This endpoint represents the basic usage of the `reghdfe` command to estimate a linear regression model with one set of absorbed fixed effects. ### Method POST ### Endpoint /reghdfe ### Parameters #### Query Parameters - **dependent_variable** (string) - Required - The dependent variable. - **independent_variables** (string) - Required - The independent variables. - **absorb** (string) - Required - The variable(s) to absorb as fixed effects. ### Request Example ```json { "dependent_variable": "price", "independent_variables": "weight length", "absorb": "rep78" } ``` ### Response #### Success Response (200) - **coefficients** (object) - Estimated coefficients. - **standard_errors** (object) - Standard errors for the coefficients. - **r_squared** (float) - R-squared value. #### Response Example ```json { "coefficients": { "weight": 100.5, "length": -50.2 }, "standard_errors": { "weight": 10.1, "length": 5.5 }, "r_squared": 0.75 } ``` ``` -------------------------------- ### Absorb Multiple Interaction Terms Source: https://context7.com/sergiocorreia/reghdfe/llms.txt Combine multiple interaction terms within the `absorb()` option to model complex fixed effects structures. For example, `absorb(idcode year#occ)` absorbs individual fixed effects and the interaction of year and occupation. ```stata reghdfe ln_w grade age ttl_exp tenure, absorb(idcode year#occ) ``` -------------------------------- ### Generate Sample Data Source: https://github.com/sergiocorreia/reghdfe/blob/master/misc/old-Benchmarks/areg_xtreg.log.txt Generates a large dataset with random variables and panel structure for benchmarking. This involves setting observations, creating variables, and defining panel identifiers. ```stata . set obs 2000000 number of observations (_N) was 0, now 2,000,000 . gen y = uniform() . gen x1 = uniform() . gen x2 = uniform() . gen x3 = uniform() . gen id = 1 + int((_n-1)/1000) . bys id: gen long t = _n . compress variable id was float now int variable t was long now int (8,000,000 bytes saved) ``` -------------------------------- ### Run Regression with projvar and reg Source: https://github.com/sergiocorreia/reghdfe/blob/master/misc/old-Benchmarks/res2fe.log.txt Compares the output of `projvar` followed by `reg` with the `reghdfe` command. This snippet demonstrates the projection step and subsequent linear regression. ```Stata *** 2) Run Our procedure . tic 37. di "twowayset" 38. twowayset hid tid 39. di "projvar" 40. projvar y x*, p(w_) 41. reg w_y w_x*, noc robust 42. drop w_* 43. toc, report ``` -------------------------------- ### Configuration and Iteration Control Source: https://github.com/sergiocorreia/reghdfe/blob/master/docs/hdfe.html Options for controlling the iteration process and version checking for the hdfe command. ```APIDOC ## Configuration Options ### Description Options to manage iteration limits and versioning for the hdfe command. ### Parameters - **maxiterations** (integer) - Optional - Specify maximum number of iterations; default is 1000. 0 means run forever until convergence. - **version** (flag) - Optional - Reports the version number and date of hdfe, and saves it in e(version). ``` -------------------------------- ### Run reghdfe (Fast) Source: https://github.com/sergiocorreia/reghdfe/blob/master/misc/old-Benchmarks/res2fe.log.txt Executes the `reghdfe` command with performance-enhancing options such as `fast`, `dof(none)`, `tol(1e-6)`, and `group(20)`. This is intended to show the optimized execution. ```Stata * Fast . tic 51. reghdfe y x*, vce(robust) absorb(tid hid) fast dof(none) tol(1e-6) keepsingletons group(20) // v(3) timeit 52. toc, report ``` -------------------------------- ### Run reghdfe (Old and Slow) Source: https://github.com/sergiocorreia/reghdfe/blob/master/misc/old-Benchmarks/res2fe.log.txt Executes the `reghdfe` command using the 'old' option, which is noted to be slower. This is for comparison purposes against newer, faster implementations. ```Stata * Old and Slow . tic 45. reghdfe y x*, vce(robust) absorb(tid hid) old 46. toc, report ``` -------------------------------- ### Stata Wrapper Program Source: https://github.com/sergiocorreia/reghdfe/blob/master/misc/old-Benchmarks/res2fe.log.txt The projvar Stata program handles syntax parsing and iterates over the provided variable list to call the Mata projection function. ```Stata program define projvar, nclass version 11 syntax varlist, [Prefix(name)] [Root(name)] [REPLACE] tempvar twoway_sample loc tif=twoWayif loc tin=twoWayin mark `twoway_sample' `tif' `tin' markout `twoway_sample' `varlist' //mata mata describe //summ `varlist' //summ `twoway_sample' // I need to make it robust to non 1,2,3... ids. if ("`prefix'" == "") { local prefix="proj_" } if ("`root'" == "") { local root="last" } foreach currvar of varlist `varlist' { local newvar="`prefix'`currvar'" if ("`replace'" != "") { local newvar="`currvar'" } else { gen `newvar'=. } //di "`currvar'" //di "`newvar'" mata projVar() /* mata currvar = st_local("currvar") newvar = st_local("newvar") printf(".") V = st_data(.,(id,t,currvar),sampleVarName) varIn=V[.,3] V[.,3]=V[.,3]:*D[.,3] aux=sparse(V) printf(".") Dy=rowsum(aux) Ty=colsum(aux) Ty=Ty[1,1..cols(aux)-1]' if (N1 29. bysort ttid: replace ttef = ttef[1] 30. gen tid = 1 31. replace tid = tid[_n-1] + 1*(ttid[_n-1]~=ttid[_n]) if _n>1 32. . . ** Dependent Variable . gen y = hhef + ttef + rnormal(0) 33. forvalues var = 1/`vars' { 34. qui replace y= y + x`var' 35. } 36. ``` -------------------------------- ### Diagnostic and Debugging Options Source: https://github.com/sergiocorreia/reghdfe/blob/master/docs/reghdfe.html Options for monitoring the execution of the reghdfe command and debugging estimation steps. ```APIDOC ## Diagnostic and Debugging Options ### Description Provides tools to monitor the progress and performance of the estimation process. ### Parameters #### Options - **verbose** (integer) - Optional - Sets the level of debugging information (0-4). 3 is recommended for debugging. - **timeit** (boolean) - Optional - Displays elapsed time for key estimation steps like map_precompute and map_solve. ``` -------------------------------- ### Manage REGHDFE Versions Source: https://context7.com/sergiocorreia/reghdfe/llms.txt Use specific versions of the package for replication or suppress version warnings. ```stata webuse nlswork, clear * Run using reghdfe version 3 (circa 2017) reghdfe ln_w grade age, absorb(idcode year) version(3) * Run using reghdfe version 5 (circa 2020) reghdfe ln_w grade age, absorb(idcode year) version(5) * Suppress version warning message reghdfe ln_w grade age, absorb(idcode year) version(5) nowarn * Check currently installed version reghdfe, version ``` -------------------------------- ### Run Basic Regression with Fixed Effects Source: https://context7.com/sergiocorreia/reghdfe/llms.txt Perform a linear regression using the absorb() option to account for a single fixed effect. ```stata * Basic syntax: reghdfe depvar [indepvars], absorb(absvars) [options] * Load sample data sysuse auto, clear * Simple regression with one fixed effect reghdfe price weight length, absorb(rep78) ``` -------------------------------- ### Regression Output Comparison Source: https://github.com/sergiocorreia/reghdfe/blob/master/misc/old-Benchmarks/res2fe.log.txt Displays the results of a linear regression using `reg` after `projvar`, and the results from `reghdfe` with different options. This section highlights the consistency of results across methods. ```Stata Linear regression Number of obs = 90,001 F(2, 89999) = 89977.76 Prob > F = 0.0000 R-squared = 0.6689 Root MSE = .99382 ------------------------------------------------------------------------------ | Robust w_y | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- w_x1 | 1.001295 .0033377 299.99 0.000 .9947528 1.007837 w_x2 | 1.000933 .0033202 301.47 0.000 .9944257 1.007441 ------------------------------------------------------------------------------ Done! (16:23:28, 0.4 seconds elapsed) ``` ```Stata (running historical version of reghdfe) HDFE Linear regression Number of obs = 90001 Absorbing 2 HDFE indicators F( 2, 88900) = 88879.02 Statistics robust to heteroskedasticity Prob > F = 0.0000 R-squared = 0.8071 Adj R-squared = 0.8047 Within R-sq. = 0.6689 Root MSE = 0.9999 ------------------------------------------------------------------------------ | Robust y | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- x1 | 1.001295 .0033583 298.16 0.000 .9947125 1.007877 x2 | 1.000933 .0033406 299.62 0.000 .9943856 1.007481 ------------------------------------------------------------------------------ Absorbed degrees of freedom: ------------------------------------------------------------------------------ Absorbed FE | Num. Coefs. = Categories - Redundant | Corr. w/xb -------------+-------------------------------------------------+-------------- i.tid | 100 100 0 | -0.0000 i.hid | 999 1000 1 | 0.0041 ------------------------------------------------------------------------------ Done! (16:23:29, 1.4 seconds elapsed) ``` ```Stata (dropped 0 singleton observations) (converged in 5 iterations) HDFE Linear regression Number of obs = 90001 ``` -------------------------------- ### Factorial Interactions Source: https://github.com/sergiocorreia/reghdfe/blob/master/docs/reghdfe.html Shows how to specify factorial interactions in `reghdfe`. ```APIDOC ## POST /reghdfe/factorial_interactions ### Description This endpoint demonstrates how to specify factorial interactions between variables in the `reghdfe` command, both in the main regression and within absorbed variables. ### Method POST ### Endpoint /reghdfe/factorial_interactions ### Parameters #### Query Parameters - **dependent_variable** (string) - Required - The dependent variable. - **independent_variables** (string) - Required - The independent variables, potentially including factorial interactions (e.g., `i.grade#i.age`). - **absorb** (string) - Optional - Variables to absorb as fixed effects, potentially including factorial interactions (e.g., `idcode#occ`). - **avge** (string) - Optional - Variables for Average Effects estimation, potentially including factorial interactions. ### Request Example ```json { "dependent_variable": "ln_w", "independent_variables": "i.grade#i.age ttl_exp tenure not_smsa", "absorb": "idcode#occ", "avge": "tenure#occ" } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message. - **interaction_terms** (array) - List of interaction terms included in the model. #### Response Example ```json { "message": "Factorial interactions processed successfully.", "interaction_terms": [ "i.grade#i.age", "idcode#occ", "tenure#occ" ] } ``` ``` -------------------------------- ### Specify Kernel for VCE Estimation Source: https://github.com/sergiocorreia/reghdfe/blob/master/docs/reghdfe.html Specifies the kernel to be used in VCE estimation when bandwidth is specified. The default is Bartlett. ```stata kernel(_str_) ``` -------------------------------- ### IV/2SLS/GMM Estimation Options Source: https://github.com/sergiocorreia/reghdfe/blob/master/docs/reghdfe.html Configuration options for instrumental-variable regressions, including estimator selection, auxiliary stage regressions, and suite selection. ```APIDOC ## IV/2SLS/GMM Estimation Options ### Description Configures the instrumental-variable estimation process, including the choice of estimator and the generation of auxiliary regressions. ### Parameters #### Options - **estimator** (string) - Optional - Specifies the estimator: 2sls (default), gmm2s, liml, or cue. - **stages** (list) - Optional - Adds and saves auxiliary regressions: first, ols, reduced, or acid. - **ffirst** (boolean) - Optional - Computes and reports first-stage statistics (requires ivreg2). - **ivsuite** (string) - Optional - Specifies the backend command: ivreg2 (default) or ivregress. ``` -------------------------------- ### Run reghdfe with specific options Source: https://github.com/sergiocorreia/reghdfe/blob/master/misc/old-Benchmarks/areg_xtreg.log.txt This command runs a linear regression with high-dimensional fixed effects, absorbing the 'id' variable. It uses the 'fast' option for speed and 'dof(none)' to not compute degrees of freedom. 'keepsingletons' is used to keep singleton observations. ```stata . reghdfe y x* , absorb(id) `vce' fast dof(none) keepsingletons // v3-fastest ``` -------------------------------- ### Postestimation: Hypothesis Testing Source: https://context7.com/sergiocorreia/reghdfe/llms.txt Perform F-tests and linear combination tests on regression coefficients. ```APIDOC ## test / lincom ### Description Perform hypothesis tests on coefficients or calculate linear combinations. ### Usage - test [expression] (Test single or multiple coefficients) - lincom [expression] (Calculate linear combinations of coefficients) - estat summarize (Summary statistics of the regression sample) ``` -------------------------------- ### Run `reghdfe` with Absorbing Fixed Effects (Old Version) Source: https://github.com/sergiocorreia/reghdfe/blob/master/misc/old-Benchmarks/areg_xtreg.log.txt Executes the `reghdfe` command using its historical version (`old`) to perform linear regression with absorbing fixed effects. This is used for benchmarking against other methods. ```stata . reghdfe y x* , absorb(id) `vce' old // v2 (running historical version of reghdfe) HDFE Linear regression Number of obs = 2000000 ``` -------------------------------- ### Run reghdfe with standard absorption Source: https://github.com/sergiocorreia/reghdfe/blob/master/misc/old-Benchmarks/areg_xtreg.log.txt Executes a linear regression with fixed effects using the standard method. ```stata . reghdfe y x* , absorb(id) `vce' // v3-slow ``` -------------------------------- ### Run `xtreg` with Fixed Effects Source: https://github.com/sergiocorreia/reghdfe/blob/master/misc/old-Benchmarks/areg_xtreg.log.txt Performs fixed-effects (within) regression using the `xtreg` command. This is another standard Stata command for panel data analysis with fixed effects. ```stata . xtreg y x*, fe `vce' Fixed-effects (within) regression Number of obs = 2,000,000 Group variable: id Number of groups = 2,000 R-sq: Obs per group: within = 0.0000 min = 1,000 between = 0.0000 avg = 1,000.0 overall = 0.0000 max = 1,000 F(3,1999) = 1.46 corr(u_i, Xb) = -0.0002 Prob > F = 0.2222 (Std. Err. adjusted for 2,000 clusters in id) ------------------------------------------------------------------------------ | Robust y | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- x1 | .0003261 .0007185 0.45 0.650 -.001083 .0017351 x2 | -.000757 .0007167 -1.06 0.291 -.0021627 .0006486 x3 | .0011787 .0006899 1.71 0.088 -.0001743 .0025316 _cons | .4993925 .000618 808.05 0.000 .4981805 .5006046 -------------+---------------------------------------------------------------- sigma_u | .00921489 sigma_e | .28849339 rho | .00101922 (fraction of variance due to u_i) r; t=7.48 16:37:05 ``` -------------------------------- ### reghdfe with Instrumental Variables Source: https://github.com/sergiocorreia/reghdfe/blob/master/docs/reghdfe.html Demonstrates how to perform instrumental variable (IV) regression using `reghdfe`. ```APIDOC ## POST /reghdfe/iv ### Description This endpoint illustrates how to use `reghdfe` for instrumental variable (IV) regression, specifying endogenous variables and their instruments. ### Method POST ### Endpoint /reghdfe/iv ### Parameters #### Query Parameters - **dependent_variable** (string) - Required - The dependent variable. - **control_variables** (string) - Required - Control variables that are not endogenous. - **endogenous_instruments** (string) - Required - A string defining endogenous variables and their instruments, e.g., "(length=head)". - **absorb** (string) - Optional - Variables to absorb as fixed effects. - **iv_suite** (string) - Optional - Specifies the IV estimation suite (e.g., 'ivregress'). ### Request Example ```json { "dependent_variable": "price", "control_variables": "weight", "endogenous_instruments": "(length=head)", "absorb": "rep78", "iv_suite": "ivregress" } ``` ### Response #### Success Response (200) - **coefficients** (object) - Estimated coefficients. - **standard_errors** (object) - Standard errors for the coefficients. - **first_stage_results** (object) - Results from the first-stage regression. #### Response Example ```json { "coefficients": { "weight": 100.5, "length": -50.2 }, "standard_errors": { "weight": 10.1, "length": 5.5 }, "first_stage_results": { "instruments_used": ["head"], "r_squared": 0.85 } } ``` ``` -------------------------------- ### Mata Projection Function Source: https://github.com/sergiocorreia/reghdfe/blob/master/misc/old-Benchmarks/res2fe.log.txt The projVar() Mata function performs the core projection calculation using pre-computed matrices stored in the root environment. ```Mata void projVar() { real matrix V, varIn, D,aux,delta,tau,varOut,A,B,CinvHHDH,AinvDDDH,C real colvector invHH,invDD,Dy,Ty real scalar N,T string scalar id, t, currvar,newvar,sampleVarName,w currvar = st_local("currvar") newvar = st_local("newvar") id=st_strscalar("twoWayid") root =st_local("root") N=readMat(root,"twoWayN1") T=readMat(root,"twoWayN2") //D=readMat(root,"twoWayD") w=st_strscalar("twoWayw") t=st_strscalar("twoWayt") sampleVarName = st_local("twoway_sample") V = st_data(.,(id,t,currvar),sampleVarName) varIn=V[.,3] if (w==""){ D = st_data(.,(id,t),sampleVarName) D = (D,J(rows(D),1,1)) } else { D = st_data(.,(id,t,w),sampleVarName) } V[.,3]=V[.,3]:*D[.,3] aux=sparse(V) //printf("3") Dy=rowsum(aux) Dy=Dy Ty=colsum(aux) Ty=Ty[1,1..cols(aux)-1]' B=readMat(root,"twoWayB") //rows(Ty) //cols(Ty) //rows(Dy) //cols(Dy) if (N