Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str8 Name byte var2 byte var3 "Sushila " . 2 "Sushila " . 2 "Sushila " 1 1 "Sushila " 2 2 "Sushila " 2 2 "Sushila " 2 2 "Sushila " 2 2 "Sushila " 2 2 "Sushila " 2 2 "Sushila " 2 2 "Sushila " 2 2 "Sushila " 2 2 "Ram " 1 1 "Ram " 2 2 "Ram " 1 1 "Ram " 2 2 "Ram " 1 1 "Ram " 1 1 "Ram " 1 1 "Ram " 1 1 "Ram " 1 1 "Ram " 1 1 "Ram " . 1 "Ram " 1 1 "Vinay" 1 1 "Vinay" 1 1 "Vinay" 1 1 "Vinay" 1 1 "Vinay" 1 1 "Vinay" 1 1 "Vinay" 2 2 "Vinay" 2 2 "Vinay" 1 1 "Vinay" 1 1 "Vinay" . 1 "Vinay" . 1 "Vinay" 1 1 "Vinay" 1 1 "Vinay" 1 1 "Vinay" 1 1 "Vinay" 1 1 end
Hi, I have the above data. I want to do the following. For every value of variable Name , I want to replace missing var2 with the value of var2 that it takes atleast 80 % within that name.
For example , for the name Sushila, var2 takes value 2 , 80% of the times (considering only non missing values of var2). So within Name taking value Sushila, I want to replace the two missing values of var2 with 2.
After replacement, var2 should look like var3.
How do I code the above in Stata.
Thanks
Comment