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" <>
To   <>
Subject   st: Using forval when one variable is not incremented
Date   Tue, 12 Aug 2003 17:25:54 -0700


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.


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;

Deborah Garvey, Ph.D.
Department of Economics
Kenna Hall
Santa Clara University
Santa Clara, CA  95053
408/554-2331 (FAX)

*   For searches and help try:

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