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

st: foreach question


From   "Ward Hagar" <[email protected]>
To   <[email protected]>
Subject   st: foreach question
Date   Thu, 13 May 2004 13:22:29 -0700

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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index