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
Related Posts with Two linked variable loops
Having Problem with the "menbreg" commandHello everyone, My name is David. I am new here. I need your help to solve the command issues that …
Rearrange panel data in STATADear all, I have several datasets I would like to merge, however, they are set up differently. What…
Change values within groups based on conditionsDear All, I have a dataset with group ID, individual ID, age, and sex of the individuals, as well a…
Configurate table with asdocHi all, I am using asdoc from SSC in Stata 13 and I am trying to configurate a little detail in a c…
Group-wise value assignmentHello Statalist, I hope everyone is fine. In my event study, I have event variable (EV) contain 110…
Subscribe to:
Post Comments (Atom)
0 Response to Two linked variable loops
Post a Comment