Hi, all.
I hate to trouble the list with such a simple problem, but I can't figure out what is wrong with my code. I am attempting to generate a series of state-specific and national time trends for a 12-year panel of data using -forval- like an obedient Stata user instead of the now-defunct -for- command.
I am running Intercooled Stata 7.0 for Win98/95/NT (Born: 11 June 2002).
Annotated log file follows:
use "D:\school finance centralization\data\StatAbstract data\stateexpY7586";
. keep fipsst pubst state tsrgex* rexcap* rgexed* rgexpw* rcapy* rpery*
> rexk12* k12pct* rppe*;
. unab vars: *79;
. local stubs: subinstr local vars "79" "", all;
. reshape long `stubs', i(fipsst) j(year);
(note: j = 75 76 77 78 79 80 81 82 83 84 85 86)
(note: k12pct75 not found)
(note: rexk1275 not found) --> OK. Missing exp data in 1975
(note: rppe75 not found)
Data wide -> long
-----------------------------------------------------------------------------
Number of obs. 52 -> 624
Number of variables 108 -> 13
j variable (12 values) -> year
xij variables:
k12pct75 k12pct76 ... k12pct86 -> k12pct
tsrgex75 tsrgex76 ... tsrgex86 -> tsrgex
rexcap75 rexcap76 ... rexcap86 -> rexcap
rgexed75 rgexed76 ... rgexed86 -> rgexed
rgexpw75 rgexpw76 ... rgexpw86 -> rgexpw
rcapy75 rcapy76 ... rcapy86 -> rcapy
rpery75 rpery76 ... rpery86 -> rpery
rexk1275 rexk1276 ... rexk1286 -> rexk12
rppe75 rppe76 ... rppe86 -> rppe
-----------------------------------------------------------------------------
. gen lrppe = ln(rppe);
(52 missing values generated)
. egen group = group(fipsst), missing;
. su group, meanonly;
. di `r(max)';
52
. forval i = 1/`r(max)' {
> gen time`i'= year - 74 if group == `i';
2. gen timep`i' = (year - 79)*(year >=80) if group == `i';
3. };
(612 missing values generated)
[<<snip>> Repeated 104 times (=52 groups *2 vars)]
Summing by group & year shows that time* and timep* are non-missing, valid only for group 1. For all other groups/year combinations, both variables are missing (=51*12 = 612).
. by group year: su time1 timep1 year fipsst;
____________________________________________________________
-> group = 1, year = 75
Variable | Obs Mean Std. Dev. Min Max
-------------+-----------------------------------------------------
time1 | 1 1 . 1 1
timep1 | 1 0 . 0 0
year | 1 75 . 75 75
fipsst | 1 1 . 1 1
<<snip>>
What am I doing wrong? It doesn't matter if I substitute the number of groups (52) for the `rmax' saved result in the -forval- command.
The program runs perfectly if I substitute -for- commands for the -forval- loop:
for num 1/`r(max)': gen timeX = (year - 74)*(group == X);
for num 1/52: gen timepX = (year - 79)*(group == X)*(year >=80);
Thanks for any assistance you care to offer.
Deb Garvey
******************************
Deborah Garvey, Ph.D.
Department of Economics
Kenna Hall
Santa Clara University
Santa Clara, CA 95053
408/554-5580
408/554-2331 (FAX)
[email protected]
http://lsb.scu.edu/~dgarvey
**********************************
*
* 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/