Hi statalist,

Please consider the following example data

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str8 id float(round healthshock cohort)
"IN010001" 1 0 1
"IN010001" 2 1 1
"IN010001" 3 0 1
"IN010001" 4 0 1
"IN010001" 5 1 1
"IN010002" 1 1 1
"IN010002" 2 1 1
"IN010002" 3 0 1
"IN010002" 4 0 1
"IN010002" 5 0 1
"IN010003" 1 1 1
"IN010003" 2 1 1
"IN010003" 3 0 1
"IN010003" 4 1 1
"IN010003" 5 1 1
"IN010004" 1 0 1
"IN010004" 2 0 1
"IN010004" 3 0 1
"IN010004" 4 0 1
"IN010004" 5 0 1
"IN010005" 1 1 1
"IN010005" 2 1 1
"IN010005" 3 0 1
"IN010005" 4 0 1
"IN010005" 5 1 1
"IN010006" 1 0 1
"IN010006" 2 0 1
"IN010006" 3 0 1
"IN010007" 1 1 1
"IN010007" 2 1 1
"IN010007" 3 0 1
"IN010007" 4 0 1
"IN010007" 5 0 1
"IN010008" 1 0 1
"IN010008" 2 0 1
"IN010008" 3 0 1
"IN010008" 4 1 1
"IN010008" 5 0 1
"IN010009" 1 1 1
"IN010009" 2 1 1
"IN010009" 3 0 1
"IN010009" 4 0 1
"IN010009" 5 0 1
"IN010010" 1 0 1
"IN010010" 2 0 1
"IN010010" 3 0 1
"IN010010" 4 0 1
"IN010010" 5 0 1
"IN010011" 1 1 1
"IN010011" 2 0 1
"IN010011" 3 0 1
"IN010011" 4 0 1
"IN010011" 5 1 1
"IN010012" 1 0 1
"IN010012" 2 0 1
"IN010012" 3 0 1
"IN010012" 4 0 1
"IN010012" 5 0 1
"IN010013" 1 0 1
"IN010013" 2 0 1
"IN010013" 3 1 1
"IN010013" 4 0 1
"IN010013" 5 1 1
"IN010014" 1 0 1
"IN010014" 2 0 1
"IN010014" 3 0 1
"IN010014" 4 0 1
"IN010014" 5 1 1
"IN010015" 1 0 1
"IN010015" 2 1 1
"IN010015" 3 0 1
"IN010015" 4 0 1
"IN010015" 5 1 1
"IN010016" 1 0 1
"IN010016" 2 0 1
"IN010016" 3 0 1
"IN010016" 4 0 1
"IN010016" 5 0 1
"IN010017" 1 0 1
"IN010017" 2 0 1
"IN010017" 3 0 1
"IN010017" 4 0 1
"IN010017" 5 1 1
"IN010018" 1 0 1
"IN010018" 2 0 1
"IN010018" 3 0 1
"IN010018" 4 0 1
"IN010018" 5 0 1
"IN010019" 1 0 1
"IN010019" 2 1 1
"IN010019" 3 0 1
"IN010019" 4 1 1
"IN010019" 5 0 1
"IN010020" 1 0 1
"IN010020" 2 0 1
"IN010020" 3 0 1
"IN010020" 4 0 1
"IN010020" 5 0 1
"IN010021" 1 0 1
"IN010021" 2 0 1
"IN010021" 3 0 1
"IN010021" 4 0 1
"IN010021" 5 1 1
"IN010022" 1 0 1
"IN010023" 1 0 1
"IN010023" 2 0 1
"IN010023" 3 0 1
"IN010023" 4 0 1
"IN010023" 5 1 1
"IN010024" 1 0 1
"IN010024" 2 1 1
"IN010024" 3 0 1
"IN010024" 4 1 1
"IN010024" 5 1 1
"IN010025" 1 0 1
"IN010025" 2 0 1
"IN010025" 3 0 1
"IN010025" 4 0 1
"IN010025" 5 0 1
"IN010026" 1 0 1
"IN010026" 2 0 1
"IN010026" 3 1 1
"IN010026" 4 1 1
"IN010026" 5 1 1
"IN010027" 1 0 1
"IN010027" 2 1 1
"IN010027" 3 0 1
"IN010027" 4 0 1
"IN010027" 5 1 1
"IN010028" 1 0 1
"IN010028" 2 0 1
"IN010028" 3 0 1
"IN010028" 4 0 1
"IN010028" 5 0 1
"IN010029" 1 0 1
"IN010029" 2 0 1
"IN010029" 3 0 1
"IN010029" 4 1 1
"IN010029" 5 1 1
"IN010030" 1 0 1
"IN010030" 2 0 1
"IN010030" 3 1 1
"IN010030" 4 1 1
"IN010030" 5 0 1
"IN010031" 1 1 1
"IN010031" 2 0 1
"IN010031" 3 0 1
"IN010031" 4 0 1
"IN010031" 5 1 1
"IN010032" 1 0 1
"IN010032" 2 0 1
"IN010032" 3 1 1
"IN010032" 4 0 1
"IN010032" 5 0 1
"IN010033" 1 0 1
"IN010033" 2 0 1
"IN010033" 3 0 1
"IN010033" 4 0 1
"IN010033" 5 0 1
"IN010034" 1 0 1
"IN010034" 2 0 1
"IN010034" 3 0 1
"IN010034" 4 1 1
"IN010034" 5 1 1
"IN010035" 1 0 1
"IN010035" 2 0 1
"IN010035" 3 0 1
"IN010035" 4 0 1
"IN010035" 5 0 1
"IN010036" 1 0 1
"IN010036" 2 0 1
"IN010036" 3 1 1
"IN010036" 4 1 1
"IN010036" 5 1 1
"IN010037" 1 1 1
"IN010037" 2 0 1
"IN010037" 3 0 1
"IN010037" 4 0 1
"IN010037" 5 1 1
"IN010038" 1 0 1
"IN010038" 2 0 1
"IN010038" 3 0 1
"IN010038" 4 1 1
"IN010038" 5 0 1
"IN010039" 1 0 1
"IN010039" 2 1 1
"IN010039" 3 0 1
"IN010039" 4 0 1
"IN010039" 5 0 1
"IN010040" 1 1 1
"IN010040" 2 1 1
"IN010040" 3 0 1
"IN010040" 4 0 1
"IN010040" 5 0 1
"IN010041" 1 0 1
"IN010041" 2 1 1
"IN010041" 3 0 1
"IN010041" 4 1 1
"IN010041" 5 0 1
"IN010042" 1 0 1
"IN010042" 2 1 1
"IN010042" 3 0 1
"IN010042" 4 0 1
"IN010042" 5 1 1
"IN010043" 1 1 1
"IN010043" 2 1 1
"IN010043" 3 0 1
"IN010043" 4 0 1
"IN010043" 5 1 1
"IN010044" 1 0 1
"IN010044" 2 0 1
"IN010044" 3 0 1
"IN010044" 4 0 1
"IN010044" 5 1 1
"IN010045" 1 1 1
"IN010045" 2 0 1
"IN010045" 3 0 1
"IN010045" 4 0 1
"IN010045" 5 0 1
"IN010046" 1 0 1
"IN010046" 2 1 1
"IN010046" 3 0 1
"IN010046" 4 0 1
"IN010046" 5 0 1
"IN010047" 1 0 1
"IN010047" 2 1 1
"IN010047" 3 0 1
"IN010047" 4 0 1
"IN010047" 5 1 1
"IN010048" 1 0 1
"IN010048" 2 0 1
"IN010048" 3 0 1
"IN010048" 4 0 1
"IN010048" 5 1 1
"IN010049" 1 0 1
"IN010049" 2 0 1
"IN010049" 3 0 1
"IN010049" 4 0 1
"IN010049" 5 1 1
"IN010050" 1 0 1
"IN010050" 2 0 1
"IN010050" 3 0 1
"IN010050" 4 0 1
"IN010050" 5 0 1
"IN010051" 1 0 1
"IN010051" 2 0 1
"IN010051" 3 0 1
"IN010051" 4 0 1
"IN010051" 5 0 1
"IN010052" 1 1 1
"IN010052" 2 0 1
"IN010052" 3 0 1
"IN010052" 4 0 1
"IN010052" 5 1 1
"IN010053" 1 0 1
"IN010053" 2 0 1
"IN010053" 3 0 1
"IN010053" 4 0 1
"IN010053" 5 0 1
"IN010054" 1 0 1
"IN010054" 2 0 1
"IN010054" 3 0 1
"IN010054" 4 1 1
"IN010054" 5 1 1
"IN010055" 1 0 1
"IN010055" 2 0 1
"IN010055" 3 0 1
"IN010055" 4 0 1
"IN010055" 5 0 1
"IN010056" 1 0 1
"IN010056" 2 0 1
"IN010056" 3 0 1
"IN010056" 4 1 1
"IN010056" 5 1 1
"IN010057" 1 0 1
"IN010057" 2 0 1
"IN010057" 3 0 1
"IN010057" 4 0 1
"IN010057" 5 1 1
"IN010058" 1 0 1
"IN010058" 2 0 1
"IN010058" 3 0 1
"IN010058" 4 0 1
"IN010058" 5 0 1
"IN010059" 1 0 1
"IN010059" 2 0 1
"IN010059" 3 0 1
"IN010059" 4 0 1
"IN010059" 5 1 1
"IN010060" 1 0 1
"IN010060" 2 0 1
"IN010060" 3 0 1
"IN010060" 4 0 1
"IN010060" 5 0 1
"IN010061" 1 0 1
"IN010062" 1 0 1
"IN010062" 2 0 1
"IN010062" 3 0 1
"IN010062" 4 0 1
"IN010062" 5 0 1
"IN010063" 1 0 1
"IN010063" 2 0 1
"IN010063" 3 1 1
"IN010063" 4 0 1
"IN010063" 5 0 1
"IN010064" 1 0 1
"IN010064" 2 1 1
"IN010064" 3 0 1
"IN010064" 4 0 1
"IN010064" 5 0 1
"IN010065" 1 0 1
"IN010065" 2 0 1
"IN010065" 3 0 1
"IN010065" 4 0 1
"IN010065" 5 1 1
"IN010066" 1 0 1
"IN010066" 2 0 1
"IN010066" 3 0 1
"IN010066" 4 0 1
"IN010066" 5 0 1
"IN010067" 1 0 1
"IN010067" 2 0 1
"IN010067" 3 0 1
"IN010067" 4 0 1
"IN010067" 5 1 1
"IN010068" 1 0 1
"IN010068" 2 0 1
"IN010068" 3 0 1
"IN010068" 4 0 1
"IN010068" 5 0 1
"IN010069" 1 0 1
"IN010069" 2 1 1
"IN010069" 3 0 1
"IN010069" 4 0 1
"IN010069" 5 1 1
"IN010070" 1 0 1
"IN010070" 2 0 1
"IN010070" 3 0 1
"IN010070" 4 0 1
"IN010070" 5 0 1
"IN010071" 1 0 1
"IN010071" 2 0 1
"IN010071" 3 1 1
"IN010071" 4 0 1
"IN010071" 5 0 1
"IN010072" 1 0 1
"IN010072" 2 0 1
"IN010072" 3 0 1
"IN010072" 4 1 1
"IN010072" 5 1 1
"IN010073" 1 0 1
"IN010073" 2 1 1
"IN010073" 3 1 1
"IN010073" 4 0 1
"IN010073" 5 0 1
"IN010074" 1 0 1
"IN010074" 2 1 1
"IN010074" 3 0 1
"IN010074" 5 0 1
"IN010075" 1 0 1
"IN010075" 2 1 1
"IN010075" 3 0 1
"IN010075" 4 0 1
"IN010075" 5 1 1
"IN010076" 1 0 1
"IN010076" 2 1 1
"IN010076" 3 0 1
"IN010076" 4 0 1
"IN010076" 5 1 1
"IN010077" 1 1 1
"IN010077" 2 1 1
"IN010077" 3 0 1
"IN010077" 4 1 1
"IN010077" 5 0 1
"IN010078" 1 1 1
"IN010078" 2 0 1
"IN010078" 3 0 1
"IN010079" 1 0 1
"IN010079" 2 0 1
"IN010079" 3 1 1
"IN010079" 4 1 1
"IN010079" 5 0 1
"IN010080" 1 0 1
"IN010080" 2 1 1
"IN010080" 3 1 1
"IN010080" 4 0 1
"IN010080" 5 1 1
"IN010081" 1 1 1
"IN010081" 2 1 1
"IN010081" 3 0 1
"IN010081" 4 0 1
"IN010081" 5 1 1
"IN010082" 1 1 1
"IN010082" 2 0 1
"IN010082" 3 1 1
"IN010082" 4 1 1
"IN010082" 5 0 1
"IN010083" 1 1 1
"IN010083" 2 0 1
"IN010083" 3 0 1
"IN010083" 4 0 1
"IN010083" 5 1 1
"IN010084" 1 0 1
"IN010084" 2 1 1
"IN010084" 3 0 1
"IN010084" 4 0 1
"IN010084" 5 0 1
"IN010085" 1 1 1
"IN010085" 2 0 1
"IN010085" 3 0 1
"IN010085" 4 0 1
"IN010085" 5 0 1
"IN010086" 1 1 1
"IN010086" 2 1 1
"IN010086" 3 0 1
"IN010086" 4 1 1
"IN010086" 5 0 1
"IN010087" 1 0 1
"IN010087" 2 0 1
"IN010087" 3 0 1
"IN010087" 4 0 1
"IN010087" 5 0 1
"IN010088" 1 0 1
"IN010088" 2 0 1
"IN010088" 3 1 1
"IN010088" 4 0 1
"IN010088" 5 0 1
"IN010089" 1 0 1
"IN010089" 2 0 1
"IN010089" 3 0 1
"IN010089" 4 0 1
"IN010089" 5 0 1
"IN010090" 1 0 1
"IN010090" 2 0 1
"IN010090" 3 0 1
"IN010090" 4 1 1
"IN010090" 5 0 1
"IN010091" 1 1 1
"IN010091" 2 0 1
"IN010091" 3 0 1
"IN010091" 4 1 1
"IN010091" 5 0 1
"IN010092" 1 1 1
"IN010092" 2 0 1
"IN010092" 3 0 1
"IN010092" 4 0 1
"IN010092" 5 0 1
"IN010093" 1 0 1
"IN010093" 2 0 1
"IN010093" 3 0 1
"IN010093" 4 0 1
"IN010093" 5 0 1
"IN010094" 1 0 1
"IN010094" 2 0 1
"IN010094" 3 0 1
"IN010094" 4 0 1
"IN010094" 5 1 1
"IN010095" 1 0 1
"IN010095" 2 0 1
"IN010095" 3 1 1
"IN010095" 4 0 1
"IN010095" 5 0 1
"IN010096" 1 1 1
"IN010096" 2 0 1
"IN010096" 3 1 1
"IN010096" 4 1 1
"IN010096" 5 0 1
"IN010097" 1 1 1
"IN010097" 2 0 1
"IN010097" 3 0 1
"IN010097" 4 1 1
"IN010097" 5 1 1
"IN010098" 1 0 1
"IN010098" 2 1 1
"IN010098" 3 0 1
"IN010098" 4 0 1
"IN010098" 5 1 1
"IN010099" 1 0 1
"IN010099" 2 0 1
"IN010099" 3 0 1
"IN010099" 4 0 1
"IN010099" 5 1 1
"IN010100" 1 0 1
"IN010100" 2 1 1
"IN010100" 3 0 1
"IN010100" 4 0 1
"IN010100" 5 0 1
"IN011001" 1 0 0
"IN011001" 2 0 0
"IN011001" 3 0 0
"IN011001" 4 0 0
"IN011001" 5 0 0
"IN011002" 1 0 0
"IN011002" 2 1 0
"IN011002" 3 0 0
"IN011002" 4 0 0
"IN011002" 5 0 0
"IN011003" 1 0 0
"IN011003" 2 0 0
"IN011003" 3 0 0
end
The data contains information on health shock faced by households in different rounds. The data comes from two cohorts: cohort=1 and cohort=0.

For cohort=1, I want to find out whether a household has faced a health shock any time during rounds 1,2,3. Thus, a household which has experienced health shock in either 1, or 2, or 3 or any combinations of these rounds, will have a value of 1. A household which has not experienced health shock in any of these three rounds will have value of 0.

I tried the following code which I think was wrong because it showed there isn't any household that hasn't faced health shock in any of these three rounds:
Code:
gen healthshock_3=.
replace healthshock_3=1 if healthshock==1&round==1|healthshock==1&round==2|healthshock==1&round==3 & cohort==1
replace healthshock_3=0 if healthshock==0&round==1 & healthshock==0&round==2 & healthshock==0&round==3 & cohort==1
What I'm trying to obtain is something like the following:
Code:
keep if cohort==1
drop if round==4
drop if round==5
sort id round
by id:egen cumul_hs=total( healthshock ),missing
tab cumul_hs
recode cumul_hs 2/3=1 /*to obtain binary variable: whether faced any health shock from 1 to 3 or not*/
tab cumul_hs

 cumul_hs |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |      2,841       48.22       48.22
          1 |      3,051       51.78      100.00
------------+-----------------------------------
      Total |      5,892      100.00
, but without deleting cohort=0 and rounds 4 and 5.

Would appreciate any help in this regard.

Thanks,