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
Multiple imputationCan we divide into separate steps the variables with missing data according to their type while mult…
Create a variable to indicate overlappingHello all, I have the dataset as follows. In each observation I have carrier, time(yq), and market(…
Multivariable logistic regression missing out categoriesHi all, I'm trying to a multivariable logistic regression analysis of some data, with one of the var…
Query in Breusch-Pagan test for panel dataHello everyone, I am new to this forum. I would like to test my panel data model for Heterskedastici…
Query about interaction terms in fixed effects panel dataHi, I have a question about fixed effects panel data interaction terms: Here is my code, xtreg D…
Subscribe to:
Post Comments (Atom)
0 Response to Help with loopingn
Post a Comment