I would like to create time use variables in R using UKTUS database.
UKTUS records people activities for every 10 minutes defined by the dataset as act1_1
, act1_2
,...,act1_144
variables (144 x 10 minutes).
Each activity is broken down to different coding scheme. For example SLEEP is coded as follows:
110 Sleep 111 In bed not asleep 120 Sick in bed
I created a matrix in R with 129 columns and 16533 rows.
Activities <-uktus15_diary_wide[,c ("serial", "pnum","ddayw","DVAge", "dmonth", "dyear","WhenDiary","AfterDiaryDay","WhereStart","WhereEnd","RushedD","Ordinary","KindOfDay","Trip","enjm1","act1_1, "act1_2", "act1_3", "act1_4", "act1_5", "act1_6", "act1_7", "act1_8", "act1_9", "act1_10", "act1_11", "act1_12", "act1_13", "act1_14","act1_15", "act1_16", "act1_17", "act1_18", "act1_19", " "act1_21", "act1_22", "act1_23", "act1_24", "act1_25", "act1_26", "act1_27", "act1_28", "act1_29", "act1_30",
"act1_31", "act1_32", "act1_33", "act1_34", "act1_35", "act1_36", "act1_37", "act1_38", "act1_39", "act1_40",
"act1_41", "act1_42", "act1_43", "act1_44", "act1_45", "act1_46", "act1_47", "act1_48", "act1_49", "act1_50",
"act1_51", "act1_52", "act1_53", "act1_54", "act1_55", "act1_56", "act1_57", "act1_58", "act1_59", "act1_60",
"act1_61", "act1_62", "act1_63", "act1_64", "act1_65", "act1_66", "act1_67", "act1_68", "act1_69", "act1_70",
"act1_71", "act1_72", "act1_73", "act1_74", "act1_75", "act1_76", "act1_77", "act1_78", "act1_79", "act1_80",
"act1_81", "act1_82", "act1_83", "act1_84", "act1_85", "act1_86", "act1_87", "act1_88", "act1_89", "act1_90",
"act1_91", "act1_92", "act1_93", "act1_94", "act1_95", "act1_96", "act1_97", "act1_98", "act1_99", "act1_100",
"act1_101", "act1_102", "act1_103", "act1_104", "act1_105", "act1_106", "act1_107", "act1_108", "act1_109",
"act1_110", "act1_111", "act1_112", "act1_113", "act1_114")]
For TV variable I generated the code in Stata but I don't know how to rewrite for R. Could somebody help me please?
I have 144 time steps; and activities between 8209 and 8230 are related to TV watching.
Stata commands for radio/tv variables are the following:
generate tv = 0
generate radio = 0
forvalues i = 1/144 {
replace tv = tv+10 if (act1_`i’ > 8209 & act1_`i’ < 8230)
replace radio = radio+10 if (act1_`i’ > 8229 & act1_`i’ < 8321)
}