I have a dataset that consists of sub-boroughs of New York City, this is a panel dataset ranging from the years 2004 to 2018. I want to created new observations weighted by population for certain sub-boroghts. For example from the code below I have the variable subb which contains the sub-boroughs of NYC, then I have other variables containing the percent unemployment rate, the percent disabled and others for each sub-borough. I want to create a new variable with the population weighted average for certain sub-boroughs. For example, I want to create new observations that are the population weighted sum of the sub-borough Astoria and the sub-borough Bayride? Does anyone know how I can do this across all the years above and for the sub-boroughs I want? If this is not clear I will re-write this.
* Example generated by -dataex-. To install: ssc install dataex
clear
input str36 subb byte year float(racial_diversity unemployment) long population float newUHF
"Astoria" 4 .722033 .07815441 205469 401
"Astoria" 5 .6706185 .07532848 196854 401
"Astoria" 6 .670942 .101195 190247 401
"Astoria" 7 .669935 .0639242 175303 401
"Astoria" 8 .63676 .0640418 178480 401
"Astoria" 9 .608331 .104931 176394 401
"Astoria" 10 .672337 .12997 166666 401
"Astoria" 11 .655666 .109072 170174 401
"Astoria" 12 .635969 .0782825 165035 401
"Astoria" 13 .679418 .0962559 178585 401
"Astoria" 14 .669118 .0897409 182860 401
"Astoria" 15 .656954 .0610463 175460 401
"Astoria" 16 .668059 .0556043 171988 401
"Astoria" 17 .680867 .0461374 164321 401
"Astoria" 18 .665779 .0441811 160871 401
"Bay Ridge" 4 .4868564 .06056965 119871 209
"Bay Ridge" 5 .5356588 .09017288 124339 209
"Bay Ridge" 6 .523746 .0814226 123447 209
"Bay Ridge" 7 .516498 .0474427 126730 209
"Bay Ridge" 8 .48276 .0494867 121390 209
"Bay Ridge" 9 .525969 .105632 128811 209
"Bay Ridge" 10 .596667 .0914809 137599 209
"Bay Ridge" 11 .568687 .0980608 132931 209
"Bay Ridge" 12 .569048 .0822029 127481 209
"Bay Ridge" 13 .57582 .0941371 127683 209
"Bay Ridge" 14 .605431 .0741944 128545 209
"Bay Ridge" 15 .601466 .0772415 122418 209
"Bay Ridge" 16 .604579 .0680491 118804 209
"Bay Ridge" 17 .635926 .0473353 123488 209
"Bay Ridge" 18 .648215 .0361489 125200 209
"Bayside/Little Neck" 4 .55809027 .04101269 116749 .
Related Posts with Creating new observations
runiform function and r(N) scalarHi, I am trying to use the runiform function to randomally select 1/3 of the observations. Unfortun…
Problem with Forest plot using midasHi everyone, I am using midas to do diagnostic accuracy meta-analysis. I have one relatively simple…
Distribution of FEHello everyone. I am trying to get the distribution of firm fixed effects (acquirer FE) when I also…
Models that allows quantitative and qualitative variablesIn a rural household’s survey, I am working with Diff. I have work with dummies for some topics such…
C plugin argumentsStataers, I wrote a C plugin that I can call using this code: Code: program r preserve versio…
Subscribe to:
Post Comments (Atom)
0 Response to Creating new observations
Post a Comment