Hi there,

I’m fairly new to Stata and would really appreciate some advice with coding.

I’m looking at time survey data, with 144 variables, each for ten minute slots of an individual’s day (running from “act1_1” to “act1_144”) and am trying to create a new variable counting every individual who went to sleep (activities defined by “110” and “111”) within an hour of using electronics (group of activities defined with codes between “7220” and “7259”).

I’ve been trying the below code to create a “sleephygiene” variable to count instances of an individual using tech within 6 time slots of going to sleep, but I keep getting a syntax error message.

forvalues i = 1/138 {
forvalues j = `= `i' + 6' {
replace sleephygiene = sleephygiene+1 if (act1_`i’ > 7219 & act1_`i’ < 7260 & act1_`j’ > 109 & act1_`j’ < 112)
}
}

Could anyone please point out where I might be going wrong?

Thanks,
Luke