Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | "Martin Weiss" <martin.weiss1@gmx.de> |
To | <statalist@hsphsun2.harvard.edu> |
Subject | st: RE: Saving loop index value |
Date | Thu, 8 Apr 2010 21:21:38 +0200 |
<> You can -save- it with the dataset. -postfile-, btw, might be a smarter choice for your problem. ******* clear* forv i=1/10{ set obs 1 gen byte myvar=`i' save myfile`i', replace drop _all } //example file # 7 u myfile7 l ******* HTH Martin -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Hollis,Michael E Sent: Donnerstag, 8. April 2010 21:09 To: statalist@hsphsun2.harvard.edu Subject: st: Saving loop index value 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/ * * 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/