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

st: Using variables in numlist of forvalue command


From   Shawn.Fultz@med.va.gov
To   statalist@hsphsun2.harvard.edu
Subject   st: Using variables in numlist of forvalue command
Date   Wed, 8 Jun 2005 10:33:21 -0500

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
        }

Any suggestions?

Thanks,
_Shawn
 









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