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

# st: AW: about 'forvalues' loop

 From "Martin Weiss" To Subject st: AW: about 'forvalues' loop Date Tue, 8 Sep 2009 13:33:25 +0200

```<>

The line

*************
bysort cy: gen kstck = 0
*************

is no different from - gen kstck = 0- as there is nothing specific about
"cy" in the -generate- statement.

You -generate- one "kstck", but then -replace- several others, like
"kstck1992". Make sure they do exist the moment you want to -replace- them!
What is the error message?

HTH
Martin

-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Marwan Elkhoury
Gesendet: Dienstag, 8. September 2009 13:30
An: statalist@hsphsun2.harvard.edu
Betreff: st: about 'forvalues' loop

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/

*
*   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–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index