Code:
* Example generated by -dataex-. To install: ssc install dataex clear input byte(id choiceoccasion) str1 alt byte chosen 1 1 "A" 0 1 1 "B" 0 1 1 "C" 1 1 2 "A" 0 1 2 "B" 0 1 2 "C" 1 1 3 "A" 1 1 3 "B" 0 1 3 "C" 0 2 4 "A" 1 2 4 "B" 0 2 4 "C" 0 2 5 "A" 0 2 5 "B" 0 2 5 "C" 1 2 6 "A" 0 2 6 "B" 1 2 6 "C" 0 end
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input byte(id choiceoccasion) str1 alt byte chosen 1 3 "A" 1 1 3 "B" 0 1 3 "C" 0 2 4 "A" 1 2 4 "B" 0 2 4 "C" 0 2 6 "A" 0 2 6 "B" 1 2 6 "C" 0 end
forvalues i = 3(3)`=_N' {
if alt[`i'] =="C" & chosen[`i'] ==1 {
local x=`i'- 2
drop in `x'/`i'
}
}
However, I noticed that this only works when no two consecutive choice occasions choose "C".
Any advice on how to do this? It would be greatly appreciated!
0 Response to How to use loops and macros to delete consecutive observations based on characteristics of the last observation in the group?
Post a Comment