[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.
Related Posts with Is there a more efficient way to replace a full variable on Stata please?
split variables and stringsDear All, I have this data set Code: * Example generated by -dataex-. For more info, type help data…
Request for second-opinion on Stata code and suggestion on how to see AAR per day (with t-stat)Second-opinion on Stata-code and request for suggestions on how to see AAR per day Hi all, Thank…
SummarizeHello, I would like to summarize for each year in (total_region_share1978, total_region_share1979, …
set scheme plotplainI am trying to set the scheme plotplain but STATA simply doesn't accept it. The error message says "…
Creating subsets from appended databaseI am interested in creating subsets from the appended dataset using uniquely identified ID. An examp…
Subscribe to:
Post Comments (Atom)
0 Response to Is there a more efficient way to replace a full variable on Stata please?
Post a Comment