foreach var of local dlist {
generate dwt`var'=`var'/wt
}
You omitted the -local-.
Nick
[email protected]
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]On Behalf Of Ward Hagar
> Sent: 13 May 2004 21:22
> To: [email protected]
> 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/