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

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


From   [email protected]
To   [email protected]
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/



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