I am using stata 15.
I have a string variable named
seriesid
region id
series id
The variable looks like:
NSA01000000000000001
For example:
NSA02000000000000001
NSA04000005000000001
NSA13000008000000001
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" }
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" } }
Phil
0 Response to extracting unique identifiers from a string variable
Post a Comment