The version of Stata I am using is Stata/MP 14.2. I am on Windows 10.
There are two methods below:
The first regression uses i.time;
the second method creates individual dummy variables for each value of "time" manually, and then regress y on these individual dummy variables.
I think the two are supposed to produce the same results, however, the sign of the coefficients flip, while other stats remain the same.
It seems that a similar question is posted here: https://www.statalist.org/forums/for...-effects-model
But it doesn't seem that the problem has been resolved, and I am not using standardization.
This is an example:
Data generating:
Code:
* generating example: clear all set obs 60 set seed 10101 gen id =_n expand 11 drop in 1/60 count bys id: gen time = _n+1999 xtset id time gen x1 = rnormal(1,7) gen x2 = rnormal(2,5) sort time id by time: gen ind = _n sort id time by id: gen T = _n gen D = 0 replace D = 1 if id > 29 gen post = 0 replace post = 1 if time >= 2005 bysort id: gen y0 = 10 + 5 * x1 + 3 * x2 + T + ind + rnormal() bysort id: gen y1 = 10 + 5 * x1 + 3 * x2 + T + ind + rnormal() if time < 2005 bysort id: replace y1 = 10 + 5 * x1 + 3 * x2 + T*5 + ind + rnormal() if time >= 2005 gen y = y0 + D * (y1 - y0)
First regression and output:
Code:
* first way of using reghdfe
reghdfe y i.D#i.time x1 x2, vce(robust) absorb(id time)
* results:
. reghdfe y i.D#i.time x1 x2, vce(robust) absorb(id time)
(MWFE estimator converged in 2 iterations)
note: 1.D#2000b.time omitted because of collinearity
note: 1.D#2001.time omitted because of collinearity
note: 1.D#2002.time omitted because of collinearity
note: 1.D#2003.time omitted because of collinearity
note: 1.D#2004.time omitted because of collinearity
note: 1.D#2005.time omitted because of collinearity
note: 1.D#2006.time omitted because of collinearity
note: 1.D#2007.time omitted because of collinearity
note: 1.D#2008.time omitted because of collinearity
note: 1.D#2009.time omitted because of collinearity
HDFE Linear regression Number of obs = 600
Absorbing 2 HDFE groups F( 11, 520) = 73420.88
Prob > F = 0.0000
R-squared = 0.9996
Adj R-squared = 0.9996
Within R-sq. = 0.9993
Root MSE = 1.0198
------------------------------------------------------------------------------
| Robust
y | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
D#time |
0 2001 | -.4300092 .3876248 -1.11 0.268 -1.191512 .3314938
0 2002 | -.5771689 .4019524 -1.44 0.152 -1.366819 .2124813
0 2003 | -.429583 .3970868 -1.08 0.280 -1.209674 .3505086
0 2004 | -.0252408 .4055941 -0.06 0.950 -.8220453 .7715637
0 2005 | -23.81867 .3902227 -61.04 0.000 -24.58527 -23.05206
0 2006 | -28.3694 .3752589 -75.60 0.000 -29.10661 -27.63219
0 2007 | -32.00615 .3955035 -80.93 0.000 -32.78314 -31.22917
0 2008 | -36.16594 .411139 -87.97 0.000 -36.97363 -35.35824
0 2009 | -40.40244 .4017046 -100.58 0.000 -41.19161 -39.61328
1 2000 | 0 (omitted)
1 2001 | 0 (omitted)
1 2002 | 0 (omitted)
1 2003 | 0 (omitted)
1 2004 | 0 (omitted)
1 2005 | 0 (omitted)
1 2006 | 0 (omitted)
1 2007 | 0 (omitted)
1 2008 | 0 (omitted)
1 2009 | 0 (omitted)
|
x1 | 4.998795 .0061697 810.22 0.000 4.986675 5.010916
x2 | 3.002194 .0087326 343.79 0.000 2.985039 3.01935
_cons | 62.15612 .1440129 431.60 0.000 61.8732 62.43904
------------------------------------------------------------------------------
Absorbed degrees of freedom:
-----------------------------------------------------+
Absorbed FE | Categories - Redundant = Num. Coefs |
-------------+---------------------------------------|
id | 60 0 60 |
time | 10 1 9 |
-----------------------------------------------------+Second regression and output:
Code:
* second way of doing the same thing"
.
. tab time, gen(year)
time | Freq. Percent Cum.
------------+-----------------------------------
2000 | 60 10.00 10.00
2001 | 60 10.00 20.00
2002 | 60 10.00 30.00
2003 | 60 10.00 40.00
2004 | 60 10.00 50.00
2005 | 60 10.00 60.00
2006 | 60 10.00 70.00
2007 | 60 10.00 80.00
2008 | 60 10.00 90.00
2009 | 60 10.00 100.00
------------+-----------------------------------
Total | 600 100.00
. reghdfe y c.D#(c.year2-year10) x1 x2, absorb(id time) vce(robust)
(MWFE estimator converged in 2 iterations)
HDFE Linear regression Number of obs = 600
Absorbing 2 HDFE groups F( 11, 520) = 73420.88
Prob > F = 0.0000
R-squared = 0.9996
Adj R-squared = 0.9996
Within R-sq. = 0.9993
Root MSE = 1.0198
------------------------------------------------------------------------------
| Robust
y | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
c.D#c.year2 | .4300092 .3876248 1.11 0.268 -.3314938 1.191512
|
c.D#c.year3 | .5771689 .4019524 1.44 0.152 -.2124813 1.366819
|
c.D#c.year4 | .429583 .3970868 1.08 0.280 -.3505086 1.209674
|
c.D#c.year5 | .0252408 .4055941 0.06 0.950 -.7715637 .8220453
|
c.D#c.year6 | 23.81867 .3902227 61.04 0.000 23.05206 24.58527
|
c.D#c.year7 | 28.3694 .3752589 75.60 0.000 27.63219 29.10661
|
c.D#c.year8 | 32.00615 .3955035 80.93 0.000 31.22917 32.78314
|
c.D#c.year9 | 36.16594 .411139 87.97 0.000 35.35824 36.97363
|
c.D#c.year10 | 40.40244 .4017046 100.58 0.000 39.61328 41.19161
|
x1 | 4.998795 .0061697 810.22 0.000 4.986675 5.010916
x2 | 3.002194 .0087326 343.79 0.000 2.985039 3.01935
_cons | 45.93366 .1506753 304.85 0.000 45.63765 46.22967
------------------------------------------------------------------------------
Absorbed degrees of freedom:
-----------------------------------------------------+
Absorbed FE | Categories - Redundant = Num. Coefs |
-------------+---------------------------------------|
id | 60 0 60 |
time | 10 1 9 |
-----------------------------------------------------+Thank you!
0 Response to reghdfe produce coefficients with opposite sign
Post a Comment