Hello!
Struggling again with some coding as I am just returning to stata after a (very) long hiatus.
Idpriv = student id
acitv1-activ27 = student activity (football, band, newspaper, etc)
years1-years27 = # of years participating in the associated student activity
For student activities 3001-3008 (music groups) I would like to calculate the...
I attempted to loop over the variable list, years1-years27, but could not identify how to incorporate the conditional statement.
foreach var of varlist years1-years27 {
gen ttlyears = `var' if activ==3001 | activ==3002 | etc.
I also attempted a forval loop as well, but I knew it was wrong as I was typing because it doesn't reference the variable with the values I am conditioning on. I get the complete row total, but I only want the values for when activ1-activ27 is equal to 3001/3008.
forval `j' = 3001/3008
egen ttlyears = rowtotal (years*)
Unfortunately, I was unable to find an answer elsewhere. I was having similar issues extracting the max value. I greatly appreciate any guidance you can offer!
Struggling again with some coding as I am just returning to stata after a (very) long hiatus.
idpriv | activ1 | years1 | activ2 | years2 | activ3 | years3 | total cumulative years in 3001-3008 | max years in 3001-3008 |
1 | 3001 | 4 | 3004 | 2 | 5002 | 2 | 6 | 4 |
2 | 3003 | 2 | 1005 | 3 | 1002 | 3 | 2 | 2 |
3 | 4006 | 4 | 3007 | 3 | 3006 | 1 | 4 | 3 |
acitv1-activ27 = student activity (football, band, newspaper, etc)
years1-years27 = # of years participating in the associated student activity
For student activities 3001-3008 (music groups) I would like to calculate the...
- Cumulative number of years spent in 3001-3008 student activities
- The max value for years across 3001-3008
I attempted to loop over the variable list, years1-years27, but could not identify how to incorporate the conditional statement.
foreach var of varlist years1-years27 {
gen ttlyears = `var' if activ==3001 | activ==3002 | etc.
I also attempted a forval loop as well, but I knew it was wrong as I was typing because it doesn't reference the variable with the values I am conditioning on. I get the complete row total, but I only want the values for when activ1-activ27 is equal to 3001/3008.
forval `j' = 3001/3008
egen ttlyears = rowtotal (years*)
Unfortunately, I was unable to find an answer elsewhere. I was having similar issues extracting the max value. I greatly appreciate any guidance you can offer!
Comment