[CODE]
* Example generated by -dataex-. To install: ssc install dataex
clear
input str19 childspostcode float(deprivation postcode)
"BT41 4RJ" 658 .
"Bt489nl " 69 .
"BT80 9XY" 390 .
"BT79 9lz " 395 .
"Bt480eu " 68 .
"Bt31 9sg " 235 .
"BT18 0PY" 816 .
"Bt66 8zh" 332 .
"BT401ep " 367 .
"Bt13 2dz" 28 .
"Bt40" . .
end
I have 111 participant variables, I wish to change their postcode "childspostcode" into their a deprivation rate "deprivationquintile". This deprivation quintile differs for every participant postcode. Is the below syntax the most efficient way to do this in Stata?
replace childspostcode="658" if childspostcode == "BT41 4RJ"
replace childspostcode="69" if childspostcode == "BT489NL"
replace childspostcode="390" if childspostcode == "BT80 9XY"
replace childspostcode="395" if childspostcode == "BT799LZ"
replace childspostcode="68" if childspostcode == "BT480EU"
replace childspostcode="235" if childspostcode == "BT319SG"
replace childspostcode="816" if childspostcode == "BT180PY"
replace childspostcode="332" if childspostcode == "BT668ZH"
replace childspostcode="367" if childspostcode == "BT401EP"
replace childspostcode="28" if childspostcode == "BT132DZ" etc etc etc.
Then I destringed "childspostcode": destring childspostcode, generate(deprivation)
and recoded "childspostcode" into their deprivation quintile: recode deprivation (1/178=1) (179/356=2) (356/534=3) (535/712=4) (713/890=5), gen(deprivationquintile)
Many thanks for your guidance.
0 Response to Is there a more efficient way to replace a full variable on Stata please?
Post a Comment