Code:
******************************************************************************** isid person day sort person day save "orgdata" , replace ******************************************************************************** ******************************************************************************** drop if inrange(day, 1, 59) qui su day , meanonly qui forvalues i = 1/`=ceil(r(max)/60)' { bysort person : gen byte d60 = sum(((day-day[1]) >=60)) == 1 bysort person : drop if sum(d60) == 0 capture confirm variable d60 if ( _rc == 111 ) { continue , break } tempfile d60`i' preserve keep if d60 keep person day save "`d60`i''" , replace restore local d60fls = "`d60fls'" + " " + regexr("`d60`i''", "^.*\\", "") capture drop d60 } clear foreach fn of local d60fls { append using `c(tmpdir)'/`fn' } qui merge 1:1 person day using "orgdata", gen(d60) assert(match using) gen byte wanted2 = ( day == 0 ) | ( d60 == 3 ) sort person day drop d60 ******************************************************************************** ******************************************************************************** list , sepby(person) list if want != wanted2 ********************************************************************************
Code:
. list , sepby(person) +-------------------------------+ | person day want wanted2 | |-------------------------------| 1. | 1 0 1 1 | 2. | 1 96 1 1 | 3. | 1 109 0 0 | 4. | 1 111 0 0 | 5. | 1 115 0 0 | 6. | 1 172 1 1 | |-------------------------------| 7. | 2 0 1 1 | 8. | 2 45 0 0 | 9. | 2 90 1 1 | 10. | 2 115 0 0 | 11. | 2 145 1 0 | +-------------------------------+ . list if want != wanted2 +-------------------------------+ | person day want wanted2 | |-------------------------------| 11. | 2 145 1 0 | +-------------------------------+
0 Response to replacement
Post a Comment