I am trying to create a variable "IN" that takes value from existing variables "IN_1 IN_2 IN_3 IN_4".
But it should fill from the variable which has the least number of missing value for that country. For eg in the pasted dataex for USA "IN_1" has least number of missing observations so IN = IN_1
But for Sweden "IN_2" has least number of missing observation so for Sweden IN = IN_2.
Also, how can I reduce the number of digits after the decimal to two in all the observations.
Please help. Thank you!!
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float quarters str13 Country double(IN_1 IN_2 IN_3 IN_4) 100 "Sweden" 10 13.2733333326667 . 13.27 101 "Sweden" 10 14.3566666663333 . 14.36 102 "Sweden" 10 13.026666666 . 13.03 103 "Sweden" . 12.2099999996667 . 12.34 104 "Sweden" . 9 . . 105 "Sweden" . . . . 106 "Sweden" 12 14.566666666 . . 100 "USA" .125 . . . 101 "USA" .125 . . . 102 "USA" 1.125 . . . 103 "USA" 1.625 1.59 2.25 . 104 "USA" . 2.01 2.5 1.875 105 "USA" . 2.3 3 2.375 106 "USA" 2.375 2.38666666666667 3 2.375 107 "USA" 2.208333333333333 2.31666666666667 3 2.375 end format %tq quarters
0 Response to Forming new variable using several existing variables
Post a Comment