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

RE:RE:st: Using forval when one variable is not incremented


From   "Deborah Garvey" <DGarvey@scu.edu>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE:RE:st: Using forval when one variable is not incremented
Date   Wed, 13 Aug 2003 09:29:53 -0700

Thank you, Philippe and Nick, for your help.  I had a feeling the solution involved a local macro, which I do not handle expertly.

Will give it a go,

Deb

-------------------------------------------------------------------------------

From: philippe.vankerm@ceps.lu 
Subject: RE:st: Using forval when one variable is not incremented
Date: Wed, 13 Aug 2003 09:36:19 +0200

-------------------------------------------------------------------------------

Deborah,


Here is a suggestion. See Nick Cox's columns in the Stata Journal for more 
on this and similar issues.

The trick is to initialise a local macro containing the list of cpi's, and 
access each of them iteratively in the loop using a "word # of" macro 
extended function. 


  ** initialise the list of cpis separated by blanks;
 
  loc cpis "0.aaaa 0.bbbbb ... 0.887788779 ...";
  loc j 1;

  >forval i=76/86  {;
  >

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

  loc cpi : word `j++' of `cpis';
  gen tsrgex`i'  = tsgex`i'/`cpi';

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

Hope this helps,

Philippe

**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept for the presence of computer viruses.

**********************************************************************

*
*   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/

--------------------------------------------------------------------------------

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