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

st: Local variable holdovers in loop


From   Gould Philip L Maj AFIOH/RSRH <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: Local variable holdovers in loop
Date   Thu, 9 Dec 2004 14:31:57 -0600

Hi,

I'm working with Stata 7 with data from a group of variables that I'm
processing through a loop and generating process-control charts.  Stata 7
produces faster if less elegant graphs than Stata 8.  The problem is that
I'm generating a new variable `UBAR' and putting a label on my graph with
rlab:

	foreach j in 1 2 3 5 12 16 17 {
		tempvar U TOT_CASES TOT_POPN UBAR 3UCL 2UCL
		...
		sort loc stata_week_end   ***sort by location and stata date
for week ending on this date

		quietly by loc: gen U = jcs`j' / total_popn *100
		quietly by loc: egen TOT_CASES = sum( jcs`j')
		quietly by loc: egen TOT_POPN = sum(total_popn)
		quietly by loc: gen UBAR = `TOT_CASES'[_N]/`TOT_POPN'[_N] *
100
		local ubar = `UBAR'
		...
		#delimiter ;
		graph twoway `U' `UBAR' `3UCL' `2UCL' stata_week_end
		...rlab(`ubar')

The problem is that the label and the graph of UBAR aren't matching and it
appears that the variable is carrying over from previous loops.  Is there a
way to expunge the values at the close of the loop?  "drop" doesn't work
with locals.

Philip L. Gould, MD, MPH, DTMH
Major, USAF, MC
Preventive Medicine Consultant
Influenza and Respiratory Pathogen Surveillance
Deployment Health/Recruit Surveillance
Epidemiology Services Branch
Air Force Institute for Operational Health (AFIOH)
2513 Kennedy Circle, Bldg. 180
Brooks City-Base, TX 78235
Main: (210) 536-5497 or DSN 240-5497
STU:  240-3245
Office:  (210) 536-3471 or DSN: 240-3471

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