Hello,
I have a dataset that contains four variables and millions of observations. I extracted three observations as an example.
I want to look up the id names and then automatically use values from variables tot_popc and weig_sum to do calculations.
The following code is not correct to the Stata but a similar structure is the goal which is to call the id name at the first line and the bolded lines give back to the values instead of manually typing there.
if id == "af301" {
double tot_popc = 4085501.00
double weig_sum = 29461.00
gen popwt = weig_sum / tot_popc
if (popwt < 0) {
popwt = 0
}
popwt = round(popwt)
}
I am still a newbie to Stata and appreciate any suggestions and ideas. Thank you very much!
I have a dataset that contains four variables and millions of observations. I extracted three observations as an example.
id | year | tot_popc | weig_sum |
bh380 | 2021 | 4043308 | 14687 |
co712 | 1950 | 3624225 | 9852 |
af301 | 1980 | 4085501 | 29461 |
The following code is not correct to the Stata but a similar structure is the goal which is to call the id name at the first line and the bolded lines give back to the values instead of manually typing there.
if id == "af301" {
double tot_popc = 4085501.00
double weig_sum = 29461.00
gen popwt = weig_sum / tot_popc
if (popwt < 0) {
popwt = 0
}
popwt = round(popwt)
}
I am still a newbie to Stata and appreciate any suggestions and ideas. Thank you very much!
Comment