Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Using forval when one variable is not incremented


From   "Deborah Garvey" <DGarvey@scu.edu>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Using forval when one variable is not incremented
Date   Tue, 12 Aug 2003 17:25:54 -0700

Greetings.

I searched the statalist archives to see if someone has encountered the following problem.  My search turned up nothing; perhaps I am not using the proper commands?  This must surely be a common problem.

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;
};


******************************
Deborah Garvey, Ph.D.
Department of Economics
Kenna Hall
Santa Clara University
Santa Clara, CA  95053
408/554-5580
408/554-2331 (FAX)
dgarvey@scu.edu    
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/



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