*! version 4.4.0 11sep2017

Title

FixedEffects -- Mata class behind reghdfe

Syntax

To construct the object:

class FixedEffects
fixed_effects( absvars [
,
touse,
weighttype,
weightvar,
drop_singletons,
verbose])

* string absvars names of variables that identify each set of fixed effects

string touse name of dummy touse variable

string weighttype type of weight (fweight, pweight, aweight, iweight)

string weightvar name of weight variable

string drop_singletons whether to drop singleton groups or not

string verbose how much information to report
(0: report warnings, 1 to 4 reports more details, -1 is silent)

Standard usage

(optional) First, you can declare the FixedEffects object:

class FixedEffects HDFE

Then, you create the object from categorical variables, categorical-continuous interactions, etc.:

HDFE = fixed_effects(varnames)

Then you can modify the object and add important properties:

HDFE.varlist = varlist // used to report messages about all demeaned variables

HDFE.indepvars = indepvars // used to report messages about demeaned regressors

HDFE.num_clusters = # // Number of clusters

... see reghdfe.ado for more options and how to combine them

Properties and Methods

properties (factors)

Integer N number of obs

Integer M Sum of all possible FE coefs

Factors factors

Vector sample

Varlist absvars

Varlist ivars

Varlist cvars

Boolean has_intercept

RowVector intercepts

RowVector num_slopes

Integer num_singletons

Boolean save_any_fe

Boolean save_all_fe

Varlist targets

RowVector save_fe

properties (optimization options)

Real tolerance

Integer maxiter

String transform Kaczmarz Cimmino Symmetric_kaczmarz (k c s)

String acceleration Acceleration method. None/No/Empty is none\

Integer accel_start Iteration where we start to accelerate /set it at 6? 2?3?

string slope_method

Boolean prune Whether to recursively prune degree-1 edges

Boolean abort Raise error if convergence failed?

Integer accel_freq Specific to Aitken's acceleration

Boolean storing_alphas 1 if we should compute the alphas/fes

Real conlim specific to LSMR

Real btol specific to LSMR

properties (optimization objects)

BipartiteGraph bg Used when pruning 1-core vertices

Vector pruned_weight temp. weight for the factors that were pruned

Integer prune_g1 Factor 1/2 in the bipartite subgraph that gets pruned

Integer prune_g2 Factor 2/2 in the bipartite subgraph that gets pruned

Integer num_pruned Number of vertices (levels) that were pruned

properties (misc)

Integer verbose

Boolean timeit

Boolean store_sample

Real finite_condition

Real compute_rre Relative residual error: || e_k - e || / || e ||

Real rre_depvar_norm

Vector rre_varname

Vector rre_true_residual

properties (weight-specific)

Boolean has_weights

Variable weight unsorted weight

String weight_var Weighting variable

String weight_type Weight type (pw, fw, etc)

properties (absorbed degrees-of-freedom computations)

Integer G_extended Number of intercepts plus slopes

Integer df_a_redundant e(mobility)

Integer df_a_initial

Integer df_a df_a_inital - df_a_redundant

Vector doflist_M

Vector doflist_K

Vector doflist_M_is_exact

Vector doflist_M_is_nested

Vector is_slope

Integer df_a_nested Redundant due to bein nested; used for: r2_a r2_a_within rmse

properties (VCE and cluster variables)

String vcetype

Integer num_clusters

Varlist clustervars

Varlist base_clustervars

String vceextra

properties (regression-specific)

String varlist y x1 x2 x3 x4 z1 z2 z3

String depvar y

String indepvars x1 x2

Boolean drop_singletons

String absorb contents of absorb()

String select_if If condition

String select_in In condition

String model ols, iv

String summarize_stats

Boolean summarize_quietly

StringRowVector dofadjustments firstpair pairwise cluster continuous

Varname groupvar

String residuals

RowVector kept 1 if the regressors are not deemed as omitted (by partial_out+cholsolve+invsym)

String diopts

properties (output)

String cmdline

String subcmd

String title

Boolean converged

Integer iteration_count e(ic)

Varlist extended_absvars

String notes

Integer df_r

Integer df_m

Integer N_clust

Integer N_clust_list

Real rss

Real rmse

Real F

Real tss

Real tss_within

Real sumweights

Real r2

Real r2_within

Real r2_a

Real r2_a_within

Real ll

Real ll_0

methods

Void update_sorted_weights()

Matrix partial_out()

Void _partial_out() in-place alternative to partial_out()

Variables project_one_fe()

Void prune_1core()

Void _expand_1core()

Void estimate_dof()

Void estimate_cond()

Void save_touse()

Void store_alphas()

Void save_variable()

Void post_footnote()

Void post()

Void reload(copy=0)

(run this if e.g. touse changes)

methods (LSMR-specific)

Real lsmr_norm()

Vector lsmr_A_mult()

Vector lsmr_At_mult()

Additional functions

Several useful Mata functions are included. For instance,

void
reghdfe_solve_ols(HDFE
,
X,
...
)

See mata: mata desc using lreghdfe for full list of functions and classes.

Description

TBD

Example: OLS regression

TBD

sysuse auto, clear
local depvar price
local indepvars weight gear
mata: HDFE = fixed_effects("turn", "", "fweight", "trunk", 0, 2)
mata: HDFE.varlist = "`depvar' `indepvars'"
mata: HDFE.indepvars = "`indepvars'"
mata: data = HDFE.partial_out("`depvar' `indepvars'")
mata: reghdfe_solve_ols(HDFE, data, b=., V=., N=., rank=., df_r=., resid=., kept=., "vce_none")
mata: b

Remarks

TBD

Experimental/advanced functions

TBD (LSMR, Prune, Bipartite?)

Source code

reghdfe.mata;
reghdfe_bipartite.mata;
reghdfe_class.mata;
reghdfe_constructor.mata;
reghdfe_common.mata;
reghdfe_projections.mata;
reghdfe_transforms.mata;
reghdfe_accelerations.mata;
reghdfe_lsmr.mata

Also, the latest version is available online: https://github.com/sergiocorreia/reghdfe/tree/master/src

Author

Sergio Correia

http://scorreia.com

sergio.correia@gmail.com

More Information

To report bugs, contribute, ask for help, etc. please see the project URL in Github:

https://github.com/sergiocorreia/reghdfe

Acknowledgment

TBD