[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"shawnfultz" <shawn.fultz@med.va.gov> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: RE: RE: Using variables in numlist of forvalue command |

Date |
Wed, 08 Jun 2005 19:24:02 -0000 |

And worked wonderfully. Thanks, --- In statalist@yahoogroups.com, Nick Winter <nw53@c...> wrote: > At least the advice was convergent, if not *precisely* identical. > > --Nick W > > > > It 12:56 PM 6/8/2005, you wrote: > >Oh shucks, I see that Nick Winter has already > >sent the same advice. > > > >Nick > >n.j.cox@d... > > > >Nick Cox > > > > > You can't put a variable into a numlist > > > in this way. > > > > > > Try something like > > > > > > su daysupply, meanonly > > > forvalues daynum = 2/`r(max)' { > > > replace date`daynum' = date1 + `daynum' - 1 if `daynum' > > > <= daysupply > > > } > > > > > > You may know the maximum in advance, so that you > > > can simplify to say > > > > > > forvalues daynum = 2/10 { > > > replace date`daynum' = date1 + `daynum' - 1 if `daynum' > > > <= daysupply > > > } > > > > > > Nick > > > n.j.cox@d... > > > > > > Shawn.Fultz@m... > > > > > > I'm trying to change several variables in each observation. > > > The problem is that the number of variables I want to update > > > is different for each observation and this number is a > > > variable in that observation. I've tried using a forvalues > > > loop, which works if I specify a stop and start number, but I > > > cannot find a way to put a variable in the numlist allowing > > > this to change for each observation. > > > > > > Here's the command that works: > > > forvalues daynum = 2/10 { > > > replace date`daynum'=date1+`daynum'-1 > > > } > > > > > > But when I replace the 10 with the variable that tells me how > > > many date variables to change, I get a syntax error. > > > forvalues daynum = 2/daysupply { > > > replace date`daynum'=date1+`daynum'-1 > > > } > > > >* > >* 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/ > > -------------------------------------------------------- > Nicholas Winter 607.255.8819 t > Assistant Professor 607.255.4530 f > Department of Government nw53@c... e > 308 White Hall falcon.arts.cornell.edu/nw53 w > Cornell University > Ithaca, NY 14853-4601 > > * > * 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/

**References**:**Re: st: RE: RE: Using variables in numlist of forvalue command***From:*Nick Winter <nw53@cornell.edu>

- Prev by Date:
**st: Announcing new item in SSC; convert_top_lines** - Next by Date:
**Re: st: RE: Blundell and Bond (1998).** - Previous by thread:
**Re: st: RE: RE: Using variables in numlist of forvalue command** - Next by thread:
**st: diagt and accuracy** - Index(es):

© Copyright 1996–2014 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |