I am trying to calculate the duration for which students were in public, private, and homeschool during their school career while being exposed to 40 types of infection.
q37_1 and q38_1 define the start and end age of schooling reported by students for the first type of infection. I am unable to run the forvalues command when I type "forval v= a/b"
Can someone suggest a solution?
q37_1 and q38_1 define the start and end age of schooling reported by students for the first type of infection. I am unable to run the forvalues command when I type "forval v= a/b"
Can someone suggest a solution?
Code:
*********start age of infection************************************
forval k=1/40{
recode q37_`k' (14=.)
replace q38_`k'=. if q37_`k'==. //can't calculate duration of infection if intial point is missing
replace q38_`k'=. if q38_`k'>13 // excluding datapoints for beyond school age
* creating schooling variables for each type of infection
gen pubA`k'=0
gen privA`k'=0
gen homeA`k'=0
gen a=q37_`k'
gen b=q38_`k'
//calculating total years by schooling type for each infection
forval v= a/b {
replace pubA`k'=pubA`k' + 1 if q7_`v'==1 | q7_`v'==5
replace privA`k'=privA`k' + 1 if q7_`v'==2 | q7_`v'==3 | q7_`v'==4
replace homeA`k'=homeA`k' + 1 if q7_`v'==6
}
drop a b
}

Comment