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

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


From   "Steven Stillman (LMPG)" <Steven.Stillman@lmpg.dol.govt.nz>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   st: RE: How are values substituted in a -forval- statement?
Date   Fri, 29 Aug 2003 14:09:44 +1200

I'll let someone else directly answer your question on your current code.
My suggestion is that this is much easier to do if you reshape your data
into long form so it looks like:

state 	year  	pery
AZ	75	#
AZ	76	#
etc.
CO	75	#
CO	76 	#
etc.

You can then easily do what you want to do:  (1) tsset state year, (2) gen
peryt = l.perty

Steve

> -----Original Message-----
> From:	Deborah Garvey [SMTP:DGarvey@scu.edu]
> Sent:	Friday, August 29, 2003 11:45 AM
> To:	statalist@hsphsun2.harvard.edu
> Subject:	st: How are values substituted in a -forval- statement?
> 
> 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/

The information contained in this document is intended only for the
 addressee and is not necessarily the views nor the official 
communication of the Department of Labour.  All final/official papers 
which are sent from the Department will be sent by non-electronic
means, on appropriate letterhead, signed by authorised personnel.
*
*   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