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

st: How are values substituted in a -forval- statement?


From   "Deborah Garvey" <DGarvey@scu.edu>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: How are values substituted in a -forval- statement?
Date   Thu, 28 Aug 2003 16:45:21 -0700

Howdy.

I'm running Intercooled Stata 7.0 for Windows 98 (born 11 June 2002)
and in the process of making a mistake, discovered that I don't understand something fundamental about how Stata evaluates the value list in a -forval- statement.

I wanted to associate previous year's personal income with current year spending in an 11-year panel dataset (shaped wide), so I wrote the following -forval- statement:
  
 forval i=75/85 {
  gen double peryt`i+1' = pery`i';
   };

The code assigned peryt* = pery* and did not increment peryt by one year (see example below).

Question:  what did peryt`i+1' mean to Stata?

       state      Arizona                                                 pery75     11908000
      pery76     13370000      pery77     14871000      pery78     17586000
      pery79     20973000      pery80     24057000      pery81     27559000
      pery82     29068000      pery83     31916000      pery84     36900000
      pery85     40900000      pery86     44900000     peryt75     11908000
     peryt76     13370000     peryt77     14871000     peryt78     17586000
     peryt79     20973000     peryt80     24057000     peryt81     27559000
     peryt82     29068000     peryt83     31916000     peryt84     36900000
     peryt85     40900000

Thanks for your help,

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)
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