this is my first post and I have recently been using STATA for operations beyond the basic course offered by the university. I apologize if the formatting of the question is not correct and if my vocabulary is inaccurate.
What I would like to do is to replace missing values for some observations by taking them from other observations with which they share the first digits of the string.
The values I want to copy are coming from eqi2017 variable and the "shared" variable is NUTS2.
The observations I report here are in the same dataset.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str4 NUTS2 double eqi2017 "DE11" . "DE12" . "DE13" . "DE14" . "DE21" . "DE22" . "DE23" . "DE24" . "DE25" . "DE26" . "DE27" . end
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str4 NUTS2 double eqi2017 "DE1" 1.076 "DE2" 1.343 end
So far I've been using this inefficient and bulky code:
Code:
replace eqi2017=1.076 if strpos(NUTS2 , "DE1")!=0 replace eqi2017=1.343 if strpos(NUTS2 , "DE2")!=0
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str4 NUTS2 double eqi2017 "DE11" 1.076 "DE12" 1.076 "DE13" 1.076 "DE14" 1.076 "DE21" 1.343 "DE22" 1.343 "DE23" 1.343 "DE24" 1.343 "DE25" 1.343 "DE26" 1.343 "DE27" 1.343 end
It works but since I've around 100 observations to fill I am looking for a more compact and efficient manner to deal with this.
Thank you all, I hope the question is understandable and the post is properly structured.
0 Response to Replacing missing values by matching them with a different observation
Post a Comment