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
Importing several excel files: matching columnsHi everyone, I imported over 250 excel files and appended them all together to 1 dta file, by using…
Local with conditions within a loopHi everyone, I have to generate a new variable (adjusted_pri) for each country (cname) that is the r…
Format of combined histograms using -grc1leg-Hello community, Me again. I need help with output format using the -grc1leg- command combining 12 …
xtgraph option xlabUsing xtgraph, I noticed that the option xlab (..., ..., ...) doesn't work. Whether it's specified o…
Working with hierarchical dataHi, I’m working with hierarchical data from the Current Population Survey. Each household (QSTNUM) …
Subscribe to:
Post Comments (Atom)
0 Response to Help with loopingn
Post a Comment