[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Neil Shephard" <mdeasnds@fs1.ser.man.ac.uk> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Using forval when one variable is not incremented |

Date |
Wed, 13 Aug 2003 09:21:52 +0100 |

Deborah Garvey wrote... > I need to read in several years of state-level expenditure data and > would like to automate the process using -forval-. (Maybe this is not > the way to go.) > > Here's my problem. I don't have a CPI variable in the raw data, but I > need the CPI to calculate real spending. I can't -gen- the variable, > as I must clear the data at each year's iteration. All other > variables are the same each year. > > The code as currently written is below. Any help is greatly > appreciated. > > Best, > > Deb Garvey > ---------- > > forval i=76/86 { > > ***gen cpi`i' = 0.887788779; --- NO. This only works for the > selected year. > > insheet fipsst pubst state tsgex`i' sexcap`i' sgexed`i' sgexpw`i' > capy`i' pery`i' using stateexpY`i'.txt; > > **Real spending; > > gen tsrgex`i' = tsgex`i'/cpi`i'; > ...more in a similar vein > > label var tsgex`i' "Tot state genl exp in $mils"; > label var tsrgex`i' "Tot real state genl exp in $mils"; > ..more in a similar vein > > su if pubst != .; > save stateexpY`i', replace; > clear; > }; Maybe I'm missing something, but you could simply move the -gen cpi`i' = 0.88788779- line to after you've read in each years data set, thus generating the cpi`i' variable variable for each data set you are reading in. Your loop would then look like forval i=76/86 { insheet fipsst pubst state tsgex`i' sexcap`i' sgexed`i' sgexpw`i' capy`i' pery`i' using stateexpY`i'.txt; gen cpi`i' = 0.887788779; **Real spending; gen tsrgex`i' = tsgex`i'/cpi`i'; ...more in a similar vein label var tsgex`i' "Tot state genl exp in $mils"; label var tsrgex`i' "Tot real state genl exp in $mils"; ..more in a similar vein su if pubst != .; save stateexpY`i', replace; clear; }; HTH Neil Neil Shephard Genetics Statistician ARC Epidemiology Unit, University of Manchester neil.shephard@man.ac.uk neil.shephard@mindless.com "Contrariwise, if it was so, it might be; and if it were so it would be; but as it isn't, it ain't. That's logic" - Tweedledee (Alice Through the Looking Glass) * * 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/

**References**:**st: Using forval when one variable is not incremented***From:*"Deborah Garvey" <DGarvey@scu.edu>

- Prev by Date:
**RE:st: Using forval when one variable is not incremented** - Next by Date:
**RE: st: Using forval when one variable is not incremented** - Previous by thread:
**st: Using forval when one variable is not incremented** - Next by thread:
**RE:st: Using forval when one variable is not incremented** - Index(es):

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