Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Saving loop index value


From   "Hollis,Michael E" <mhollis@mwdh2o.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Saving loop index value
Date   Thu, 8 Apr 2010 12:08:38 -0700

Greetings,

I want to "keep" the value of i which indexes the "forvalues" loop in
the loop below.  I've tried including it as a macro variable (i.e., `I')
on my keep statement.  I've also tried assigning it to a new variable
and then keeping the new variable.  Neither has worked.  Can someone
tell me how to keep i in my output dataset?

Thanks in advance.

P.S. I'm new to using macros and programming in Stata.



#delimit ;
   clear all;
   log using test.log, replace;
   set more 1;
   insheet using CAT_scenario_1.csv;          
   drop cat_scenario county;
   rename max_temp_degf maxt;
   rename precip_in prcp;
   forvalues i = 0/45 {;                       
	 preserve;
	 keep if offset==`i';
	 collapse (mean) prcp maxt, by(period);
	 do bm9304_6;
	 drop sdci_bp grup_bp;
	 keep year *_bp;
	 save scenario`i', replace;
	 restore;
     };

Michael Hollis, Ph.D
Resource and Analysis Group
Water Resource Management
Metropolitan Water District of Southern California
voice: 213-217-7228  fax: 213-2176119


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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   |   Site index