set more off capt log close local jobname proxy13_2 log using `jobname', replace * proxy13 calculate 24 months' CARA ending at filing date * cfb 8928 rev to append with original * cfb 9423 tweaked to handle 18-24 months * cfb 9B30 rev to back off to (-25, -1) include proxy.doh local infile proxy_proxyR2 local outfile proxy_proxyCARA25 use `infile', clear g filing_m = int(mofd(filing_d)) su filing_d filing_m tab filing_m tab extd desc su // fixup case_code replace case_code = "COVD_01" if case_code == "COVD-01" levelsof casenr, local(cases) local monback 23 local adjok 6 local lomo 396 local himo 539 keep if suityear == 0 gen double cara = . g obsnr = _n foreach c of local cases { // local c 1126 // 9422: determine range of available abret local minavail = `lomo' forv i = `lomo'/`himo' { su abret`i' if casenr == `c', mean if r(N) > 0 { local minavail = `i' continue, break } } local maxavail = `himo' forv i = `himo'(-1)`lomo' { su abret`i' if casenr == `c', mean if r(N) > 0 { local maxavail = `i' continue, break } } // local maxavail = cond(`maxavail' < `himo', `maxavail' + 1, `maxavail') local maxavail = cond(`minavail' == `maxavail', `himo', `maxavail') local minavail = cond(`minavail' == `maxavail', `lomo', `minavail') summ filing_m if casenr == `c', meanonly // cfb 9b30 back off one month0 local fdend = r(min) local fdend = r(min) - 1 local fdst = `fdend' - `monback' local fdst = cond(`fdst' < `minavail' & `minavail' - `fdst' <= `adjok', /// `minavail', `fdst') local ok = cond(`fdst' >= `minavail' & `fdend' <= `maxavail', " ok ", " FAIL ") su obsnr if casenr == `c', mean local cc = case_code[`r(min)'] di as err "`c' `cc' min/max avail `minavail' `maxavail' need `fdst' `fdend' `ok'" %tm `fdst' " " %tm `fdend' // fix here too qui replace cara = 0 if casenr==`c' & filing_m == `fdend' + 1 forv i=`fdst'/`fdend' { qui replace cara = cara + abret`i' if casenr==`c' // di "`i' abret`i'" // su cara if casenr == `c' // qui replace cara = cara + cond(!mi(abret`i'), abret`i', 0) if casenr==`c' } } // DROP UNNEEDED OBS (no longer needed) // egen wantone = tag(casenr) // bys casenr: keep if wantone // keep only cara observations, sorted by case code, for merge keep if cara < . & cara != 0 tabstat cara,by(casenr) stat(mean N) keep case_code cara sort case_code desc save `outfile', replace log close log2html `jobname', replace