Dear all,
I am using stata 15.
I have a string variable named
seriesid
that represents
region id
and
series id
and a last element which identifies survey type, same for all regions and series. It is preceded by NSA (not seasonally adjusted).
The variable looks like:
NSA01000000000000001
.
For example:
NSA02000000000000001
represents region 2 for aggregate employment
NSA04000005000000001
represents region 4 for agricultural employment while
NSA13000008000000001
represents region 12 for public employment.
so that each region, around 8 has its respective 12 series representing the sector.
what I wanted to do is:
1. to extract a region identifier based on the the first two digit numbers next to NSA in seriesid (in bold)
2. a series identifier separated based on the series identifiers in bold in seriesid

I tried to generate the region code using the following loop, it did not change anything.
HTML Code:
gen str r_code="xx"

forval i=01/12 {
replace r_code if seriesid=="DU"
}
I also tried to use the following code
HTML Code:
local rc "AY"    "BR"    "DU"    "GO"    "HF"    "HY"    "JL"    "JN"    "KM"    "NT"    "TU"    "XR"
levelsof seriesid, l(sid)

foreach id in sid {
forval i=01/12 {
replace r_code="`rc'" if "`id'"=="NSA`i'0000000000001"
}
}
I thank you for any hint you may point me to.
Phil