bashtage / linearmodels

Additional linear models including instrumental variable and panel data models that are missing from statsmodels.
https://bashtage.github.io/linearmodels/
University of Illinois/NCSA Open Source License
930 stars 184 forks source link

Other fixed effect not included in the R2 computation #617

Open SwannChelly opened 1 month ago

SwannChelly commented 1 month ago

Dear all,

I am a bit confused by the way R2 are computed. The goal of the within transformation is to add other fixed effects without using dummy variables that would increase a lot the time of the algorithm.

However, when you start controling for several effects using 'other_effects', those controls are not stored in the 'params' attribute and therefore not used for the computation of the different R2.

Maybe I am wrong but, I feel like when you have other fixed effects, you would like to consider them as parameters and include them in the computation of the R2. In https://www.stata.com/manuals/xtxtreg.pdf page 14, this would mean that the fixed effect would be stored in the beta of equation (1'''),(2'''),(3''') and therefore impacting the evaluation of the R2.

I found rsquared_inclusive to be the overall rsquared that fit such requirement. But could it be interesting to adjust also the between and within R2 ? I feel it should be important for the between because the share of the variance captured by the inclusion of other fixed effect should be reflected by the between estimator.

Best regards, SC

bashtage commented 1 month ago

Anything that is a FE is considered as a nuisance parameter that cannot be consistently estimated. They do not have estimates, se, or contribute to R2.

This said,.it is easy to manually compute R2 from models with FE as 1-SSE_effects/TSS_constant

Where TSS does not include the effect but does include a constant. There is documentation detailing the calcs on the docs page.

bashtage commented 1 month ago

I do not agree with stata here. I'm more in the Jeff Woodbridge camp when it comes to what FE are - they are devices to estimate some types of models consistently that would not be consistent without them. But they can't be consistently estimated unlike betas and so are not treated like parameters.

SwannChelly commented 1 month ago

Thank you for your answer. I am a bit confused thought. I didn't knew about the inconsistence of the FE estimator as I thought it was a demeaning and therefore they could be estimated with a simple "mean".

However, I think understanding the part of the variance that is captured by demeaning is very much used in econ papers since it relates to the part of the variance that is being captured by common factors.

Therefore, it is why I am a bit confused by your answer. Common factors could be very well approximated with PCA and I wonder why does FE be less estimated than common factor with PCA (I am, of course, making the assumption that the axes of my PCA matches the dimension of the FE I specify).

bashtage commented 1 month ago

In the usual setup of an NT panel, N is large and T is fixed. As a result there are O(N) entity effects effect and only T observations for each, and so they cannot be consistently estimated. The T time effects can be consistently estimated, but if entered as effects they are not treated as parameters (enter them as regressors to workround this and get standard errors and estimates).

As for means, they are only consistent if you have a large number of observations. That is not the usual case in panel econometrics for entity effects.

Of course you can estimate something for the FE - only without a framework it isn't possible to give meaning to the estimate. In what I consider the best treatment of the subject, these are nuisance parameters and only devices to get to the regression coefficients when faced with certain types of omitted variable biases.

For consistency of PCA you need both N and T to be large. In this scenario, FE are also consistently estimable.

It sounds like your FE are low dimensional. If so, why not just add them as regressors?

SwannChelly commented 1 month ago

Oh I see what you meant. In my case, I wasn't mentoning the entity effects but more sector x time effect that I add in the regression as "other_effects= df["sector_time"]". It is low dimensional FE but I rather like using the within transformation than including them as dummies.

rlustermans commented 4 days ago

@bashtage: Could you clarify if the R-squared reported by rsquared_inclusive is an adjusted R-squared? If not, could you suggest a way to manually compute the adjusted R-squared using the regression output?

bashtage commented 3 days ago

You can turn a basic R2 into an adjusted R2 using the formula

$R^{2}=1-\frac{SSE}{TSS}$

$\bar{R}^{2}=1-\left(1-R^{2}\right)\times\frac{DF{den}}{DF{num}}$

where $DF{den}$ is the DF you want for the denominator and $DF{num}$ is the DF you want for the numerator. The denominator DF is short of what you think of as the null model. Sensible choices for this are usually just a constant or constant + fixed effects. The numerator DF should always be larger than the denominator DF. For example, in class OLS, the numerator is n-k (where k is the number of estimated regression coefficients, including a constant if present), and the denominator is n - const where const = 1 if the model includes a constant.

SwannChelly commented 2 days ago

@bashtage: Could you clarify if the R-squared reported by rsquared_inclusive is an adjusted R-squared? If not, could you suggest a way to manually compute the adjusted R-squared using the regression output?

For me the rsquared_inclusive is exactly the R-squared I was mentioning, an R² computed using fixed effect estimations.