Ulrich Kohler replied to Satyarth Kulshrestha
> > this is in continuation of my problem of generating number series.
> >
> > can i run a a loop like the following in STATA:
> >
> > for city = 1 to 2
> > for house = 1 to 40
> > for sample = 1 to 5
> > gen code = string(city)+string(house)+string(sample)
> > next sample
> > next house
> > next city
> >
> > i know this is not STATA syntax but i am trying to
> express the problem
> > intuitively.
>
> Not quite sure if I unterstand this correctely, but this
> seems to be possible
> without looping:
>
> .. gen str1 code = ""
> .. replace code = string(city) + string(house) + string(sample) /*
> */ if inlist(city,1,2) & inrange(house,1,40) & inrange(sample,1,5)
>
I agree with Uli.
For your problem, no looping is necessary.
The looping is supplied by Stata insofar as -generate- is
automatically carried out for every observation.
However, for your problem, as explained in my earlier posting,
you must use a format argument for -string()- in the case of
house number.
Nick
[email protected]
*
* 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/