I believe you can get the desired result by creating a
variable
measuring whether necessary info is missing, and
sorting those
"useless" observations to the end, e.g.
g miss=mi(Y,I)
bysort Firm miss (year): gen K_t = Y[1]
by firm: replace K_t=0.85*K_t[_n-1]+I_t if _n>1
but you could also drop any observations that are
"useless" but be
careful not to save over your old data...
clear
input str3 country year Y I
ALB 1989 . .
ALB 1990 . .
ALB 1991 7252145 5.277578
ALB 1992 7269795 3.772736
ALB 1993 7745880 10.85033
ALB 1994 8463700 14.01817
ALB 1995 9114887 12.99762
end
bysort co (year): drop if mi(Y) & mi(Y[_n+1])
bysort co (year): drop if mi(Y) & !mi(Y[_n+1])
drop if mi(I)
bysort co (year): gen K_t = Y[1]
by co: replace K_t=0.85*K_t[_n-1]+I if _n>1
li
you should make sure no years are skipped using
-tsset- I suppose...
On 6/6/06, Anna Gueorguieva <anna_i_g@yahoo.com>
wrote:
Dear Nick and others,
Very helpful indeed.
However I am running into a problem of missing initial
values.
I am trying to calculate similarly capital stock
K=(1-delta)*K[_n-1]+ I
where the initial K is K=Y
So, if I use your code, this is what I get:
+----------------------------------------------+
| code year Y K I |
|----------------------------------------------|
1. | ALB 1990 . . . |
2. | ALB 1991 7252145 . 5.277578 |
3. | ALB 1992 7269795 . 3.772736 |
4. | ALB 1993 7745880 . 10.85033 |
5. | ALB 1994 8463700 . 14.01817 |
and I am unable to make it "jump" to 1991 if 1990 is
missing. Overall, the sample is very unbalanced with
some countries missing up to four initial years.
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/