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

st: Re: subscripts for loop?


From   "Steichen" <[email protected]>
To   <[email protected]>
Subject   st: Re: subscripts for loop?
Date   Wed, 31 Mar 2004 19:27:06 -0500

One approach in Stata8 is:

foreach j of numlist 1/18 {
  if `j' < 10 {
     local var b0_0`j'
  }
  else {
    local var b0_`j'
  }

... do something with `var' here ...

}

Tom


----- Original Message ----- 
From: "Kenley Barrett" <[email protected]>
To: <[email protected]>
Sent: Wednesday, March 31, 2004 7:10 PM
Subject: st: subscripts for loop?


> I'm stumped on a programming problem. I need to refer to a sequence of
> variables b0_01, b0_02, b0_03 . . .  b0_18, where the subscript identifies
> an individual child of a given
> woman and the first part of the variable refers to some characteristic of
> that child. (The woman is the unit of observation, and for each woman
> there are up to 18 children observed.) My idea was to do a loop with j=1,
> then j = j+1, etc., referring to b0_j. But this won't work. My boyfriend
> suggested doing the j loop and then concatenating to b0_, but I can't
> find anything in stata on how to concatenate a number to a string.
> Does anyone have any ideas?
>
> Thanks for your help!
> Kenley
>
> *
> *   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/
>

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