Hello, I have a question regarding adding weights to survey Data.
I have individual-level data for over 100 countries. The variable L5 can take on four values, of which I want to know
the percentage representation within a Country.
First, I tried to calculate the percentages as seen under the variable perc_L5.
As it would not be precise to use this results, how can I rewrite the code to add weights to the observations?
Code:
clear input str20 Country double projection_weight byte L5 float perc_L5 "Cameroon" 11120.53503054633 1 43.4 "Chile" 10973.507432230832 1 86.8868 "Chile" 8541.300724619616 1 86.8868 "China" 211097.9105238506 1 22.35104 "Congo Brazzaville" 7753.040300652525 2 20.91743 "Croatia" 3540.037078778114 1 52.22222 "Guatemala" 4633.447452234091 1 61.63636 "Guinea" 5669.176581309484 1 51.40351 "Hungary" 2042.3258052764882 1 67.12963 "India" 370129.64921075094 98 18.004147 "Italy" 75734.34207291917 1 70.4 "Jordan" 3650.272141344148 2 39.76024 "Kuwait" 1390.7818018971584 3 16.019417 "Liberia" 3387.1228642331657 1 54.4 "Mexico" 164398.15696774196 1 69.330666 "North Macedonia" 3331.2486706403165 1 60.18518 "Panama" 3247.522338947211 2 18.518518 "Poland" 65426.710048699206 1 52.40741
I have individual-level data for over 100 countries. The variable L5 can take on four values, of which I want to know
the percentage representation within a Country.
First, I tried to calculate the percentages as seen under the variable perc_L5.
Code:
bysort Country L5: gen prop = _N by Country: replace prop = 100 * prop/_N
Comment