[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: RE: generating number series
> i need to generate a series of id codes with following protocol:
> 6 digit length
> 1st digit = 1 or 2 [stands for 2 cities from where subjects
> 2nd and 3rd digit = house number[ from 01 to 99]
> 4th digit [= 1 or 2]
> 5th digit [ 1 to 5]
> 6th digit[ 1 or 2]
> so the series would start from 101111 and end with 299252.
> can this be done in STATA? and subsequently can we
> breakdown this code to
> its constituents, eg, analyze by city or anlyze by last 2
> digits ie only
> thoser case where id ends with 52]?
Yes. My advice, once again, is to build this up as
a string variable. There is an alternative route,
building it up as an integer, but it's not
quite so intuitive to many people.
-egen, concat()- would almost do everything
for you, but your house number must be
You don't say how the variables are stored.
I'll guess everything is numeric.
gen str6 newid = string(city) + string(houseno,"02.0%f")
+ string(whateveritis) + string(somethingelse) +
Selection is then a matter of -index()- and -substr()-
e.g. last two digits are "52".
... if substr(newid,-2,2) == "52"
Analysis by city: you have a city variable, presumably.
* For searches and help try: