Hi Everyone,
I have pasted below a screenshot of my dataset and of the variables I need to work with.
I have the number of causes of death by country and year and I have to add up the number by region and by year so that I will have a variable called 2000_pneumonia_northernafrica - 2001_pneumonia_northernafrica and so on.
I would like to do this with a loop but it does not seem to work.
This is what I have tried:
levelsof year, l(years)
local causes "neonatalcauses pneumonia diarrhoea malaria aids measles injuries others total"
foreach x in `years' {
preserve
keep if `x'==`x'
foreach var in `causes' {
egen year_`var'_`x' =total (`var'), by (region)
}
restore
}
I could do this without using a loop but I am sure there must be a way. Alternatively, I rember there is a way to "see" how Stata reads the command and executes it: if I remembered how to do that I would probably understand which bit of my loop is wrong.
Thank you very much for yoru support!
Array
Related Posts with Help with loopingn
Robust or Clustered Standard ErrorsDear all, I am currently examining the impact of annual average sunset time on sleep duration of ch…
How to change a trinary variable into a binary with label in 1 lineHello. I have to recode a trinary variable "a6a" : 1=small, 2=medium, 3=large. Into a binary variab…
Generating new variables using an if functionI am trying to sort income based on marital Status and then generate new adjusted income based on ta…
Need help with combining plots and figuresI need help with the following issues: 1. Combining Plots I have the following syntax for my plots:…
Running regressions without normally distributed residualsHi, I have a question about a regression that I am running for my Bachelor thesis. I do not have no…
Subscribe to:
Post Comments (Atom)
0 Response to Help with loopingn
Post a Comment