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

st: RE: foreach question


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: foreach question
Date   Thu, 13 May 2004 21:30:02 +0100

foreach var of local dlist {
	generate dwt`var'=`var'/wt
}

You omitted the -local-. 

Nick 
n.j.cox@durham.ac.uk 

> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu]On Behalf Of Ward Hagar
> Sent: 13 May 2004 21:22
> To: statalist@hsphsun2.harvard.edu
> Subject: st: foreach question
> 
> 
> This is probably a simple question and will take longer to 
> describe than
> answer (I hope.)
> 
> Dataset:
>   I have a list of individual patients, their weight, and a series of
> variable by year (eg, d93. d94, etc) that shows how much of a 
> drug that
> they got in that year. 
> 
>  I want to do two things in a do file analysis, but this is the first:
>  For each patient's year variables generate the amount of drug divided
> by their weight. 
>     I first put the variables in a local macro dlist, and 
> showed myself
> that the marco does contain the      list by display 
> "`dlist'" (without
> the quotations I get an single number)
>    Then I did a test, dividing one variable , say d93, by weight and
> browsed to see if the results looped over all patients, which 
> it did. So
> I conclude that generate dwt`var'= `var'/wt should give me a labeled
> variable for each patient over all of their variables. (Does this make
> sense?)
> 
>    I next tried, in my do file,
> 
> capture program drop dwt
> program dwt
> 
>  foreach var of dlist {
>        generate dwt`var'=`var'/wt
> }
> and wether I then put an end statement or not, I get an unexpected end
> of file error. I'm not getting any output to browse to see if I'm
> getting close.
> 
> All help greatly apprecated.

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