[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?
attndHi I am using survey data and I want to use sample weights for estimating attnd and attk after runni…
Gravity model - PPML fixed-effect estimationDear all, I am doing a study on how Brexit can impact the EU export by using the gravity model. My …
What is the best method to test these relationships with Stata? Multiple regression? SEMDear all, I hope you can give me your opinion about this. I have to test the following relationship…
Keeping only unique combination of observations in 2 columnsHi I have observations in two columns. Many of the values get repeated. I would like to keep only un…
Selected Graphs for Panel Data CategoriesHi, I'm new to Stata and I'm trying to get some panel-times series graphs for selected countries. Sp…
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