Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: about 'forvalues' loop


From   Marwan Elkhoury <[email protected]>
To   [email protected]
Subject   st: about 'forvalues' loop
Date   Tue, 8 Sep 2009 13:29:53 +0200

dear statalist,

sorry again to bother you with some very stupid question but I'm getting stuck again on some simple matter that I believe is in the writing of scalar.

the story is that I have a panel data and I'ld like to generate a new variable called kstck (by country (cy)).

so I run this loop:

bysort cy: gen kstck = 0
reshape wide gdp gfc kstck, i(cy) j(yr)

* Calculate capital stock from 1990 to 2000 using the following formula (where gfc* is the investment in year *)

bysort cy: replace kstck1990 = gfc1990

forvalues i = 1991/2000 {
bysort cy: replace kstck`i' = .93*kstck`i-1' + gfc`i'
}

However, it is not giving me the required result of the recursive summation. why ?

any advice would be most welcome.

and many thanks in advance.

Marwan
*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index