Dear all,
I have found the problem. I now get the same estimates and standard errors. My very crude code is below. However, computations are quite slow...
webuse grunfeld, clear
egen i=group(company)
egen t=group(year)
tsset i t
forvalues v=1(25)200 {
replace kstock=. in `v'
}
capture drop orth*
qui foreach var of varlist invest mvalue kstock {
capture drop v
gen v=(invest<.&mvalue<.&kstock<.)
capture drop i
capture drop t
egen i=group(company)
egen t=group(year)
tsset i t
gen orth`var'=.
forvalues x =1/10{
capture drop qs
capture drop e2*
capture drop e3*
egen double e2=max(t) if i==`x'
egen double e3=min(t) if i==`x'
egen double e22=mean(e2)
egen double e33=mean(e3)
replace e2=e22
replace e3=e33
local a=e3
while `a'<e2 {
capture drop sqrt*
capture drop w*
capture drop dev*
capture drop fin*
capture drop ss
capture drop ss2
capture drop `var'x
capture drop ds
capture gen double `var'x=f1.`var' if i==`x' &f1.v==1
capture egen double w`var'=total(`var'x) if t>=(`a') & i==`x'
capture egen ss2=count(`var'x) if t>=(`a') & i==`x'
capture gen double w`var'2=w`var'/ss2
capture gen double dev`var'=`var'-w`var'2
capture gen double sqrt=sqrt(ss2/(ss2+1))
capture gen double fin`var'`a'=dev`var'*sqrt
capture gen double fin`var'`a'2=l1.fin`var'`a'
capture replace orth`var'=fin`var'`a'2 if t==(`a'+1) & i==`x' & v==1
local a=`a'+1
capture drop fin*
}
}
}
. reg orthinvest orthmvalue orthkstock,nocons
obs= 176
------------------------------------------------------------------------------
orthinvest | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
orthmvalue | .1137694 .0120434 9.45 0.000 .0899995 .1375393
orthkstock | .3126414 .0173844 17.98 0.000 .27833 .3469528
------------------------------------------------------------------------------
. xtabond2 invest mvalue kstock,iv(mvalue kstock) nolev orth small
obs=176
------------------------------------------------------------------------------
orthinvest | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
orthmvalue | .1137694 .0120434 9.45 0.000 .0899995 .1375393
orthkstock | .3126414 .0173844 17.98 0.000 .27833 .3469528
------------------------------------------------------------------------------
Rodolphe
PS: a better title for this thread would have been "Forward orthogonal deviations with gaps in the data".
________________________________________
From: [email protected] [[email protected]] On Behalf Of Rodolphe Desbordes [[email protected]]
Sent: 07 June 2009 18:27
To: [email protected]
Subject: st: Forward orthogonal deviations with unbalanced panel data
Dear all,
I am trying to calculate "by hand" forward orthogonal deviations. This transformation consists in subtracting the mean of the remaining future observations available in the
sample from the current observation. A weighting is introduced to equalise the variances. A more detailed explanation can be found at http://www.tinbergen.nl/~buhai/papers/publications/panel_data_econometrics.pdf , p.6. I am not sure how to handle missing values.
A) I have written the following code:
webuse grunfeld, clear
egen i=group(company)
egen t=group(year)
tsset i t
capture drop orth*
qui foreach var of varlist invest mvalue kstock{
gen orth`var'=.
forvalues x =1/10{
capture drop e2*
capture drop e3*
egen double e2=max(t) if i==`x'
egen double e3=min(t) if i==`x'
egen double e22=mean(e2)
egen double e33=mean(e3)
replace e2=e22
replace e3=e33
local a=e3
while `a'<e2 {
capture drop sqrt*
capture drop w*
capture drop dev*
capture drop fin*
capture drop ss
capture drop ss2
capture drop `var'x
capture gen double `var'x=f1.`var' if i==`x'
capture egen double w`var'=sum(`var'x) if t>=(`a') & i==`x'
capture gen double w`var'2=w`var'/(e2-(`a'))
capture gen double dev`var'=`var'-w`var'2
capture gen double sqrt=sqrt((e2-`a')/(e2-`a'+1))
capture gen double fin`var'`a'=dev`var'*sqrt
capture gen double fin`var'`a'2=l1.fin`var'`a'
capture replace orth`var'=fin`var'`a'2 if fin`var'`a'2<.
local a=`a'+1
capture drop fin*
}
}
}
And I obtain the following results:
. reg orthinvest orthmvalue orthkstock,nocons
obs 190
------------------------------------------------------------------------------
orthinvest | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
orthmvalue | .1101238 .0118567 9.29 0.000 .0867345 .1335131
orthkstock | .3100653 .0173545 17.87 0.000 .2758308 .3442999
The estimates are equivalent to those obtained with the user-written command -xtabond2- :
. xtabond2 invest mvalue kstock,iv(mvalue kstock) nolev orth
obs 190
-------------+----------------------------------------------------------------
mvalue | .1101238 .0117941 9.34 0.000 .0870077 .1332399
kstock | .3100653 .0172629 17.96 0.000 .2762306 .3439
------------------------------------------------------------------------------
B) However, with missing values:
forvalues v=1(25)200 {
replace kstock=. in `v'
}
I have tried to replace the following lines
***
capture gen double w`var'2=w`var'/(e2-(`a'))
capture gen double dev`var'=`var'-w`var'2
capture gen double sqrt=sqrt((e2-`a')/(e2-`a'+1))
***
by
***
capture gen ss=(`var'==.) if t>=(`a') & i==`x'
capture egen ss2=sum(ss) if t>=(`a') & i==`x'
capture gen double w`var'2=w`var'/(e2-(`a')-ss2)
capture gen double dev`var'=`var'-w`var'2
capture gen double sqrt=sqrt((e2-(`a')-ss2)/(e2-(`a')+1-ss2))
***
But I obtain different results (different number of observations and different estimates):
. reg orthinvest orthmvalue orthkstock,nocons
obs 182
------------------------------------------------------------------------------
orthinvest | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
orthmvalue | .1139964 .0123395 9.24 0.000 .0896476 .1383452
orthkstock | .3100502 .0177373 17.48 0.000 .2750506 .3450499
------------------------------------------------------------------------------
. xtabond2 invest mvalue kstock,iv(mvalue kstock) nolev orth
obs 176
------------------------------------------------------------------------------
invest | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
mvalue | .1137694 .0119747 9.50 0.000 .0902993 .1372395
kstock | .3126414 .0172853 18.09 0.000 .2787627 .34652
------------------------------------------------------------------------------
Obviously, I am doing something wrong. I would greatly appreciate if someone could point me in the right direction.
Yours sincerely,
Rodolphe Desbordes
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/