|
ch12.5.do:
|
49 [+]
|
webuse
grunfeld
, clear
-
/*
*! onespell 1.1.1 CFBaum 13jan2005
* locate units with internal gaps in varlist and zap all but longest spell
program onespell, rclass
version 8.2
syntax varlist(numeric) [if] [in], Saving(string) [ REPLACE NOIsily]
preserve
quietly tsset
local pv "`r(panelvar)'"
local tv "`r(timevar)'"
summarize `pv', meanonly
local n1 = r(N)
tsfill
marksample touse
tempvar testgap spell seq end maxspell keepspell wantspell
local sss "quietly"
if "`noisily'" == "noisily" {
local sss "noisily"
}
`sss' {
* testgap is panelvar if obs is usable, 0 otherwise
generate `testgap' = cond(`touse',`pv',.)
tsspell `testgap' if `testgap'<., spell(`spell') seq(`seq') end(`end')
drop if `spell'==0 | `touse'==0
* if `spell' > 1 for a unit, there are gaps in usable data
* calculate max length spell for each unit and identify
* that spell as the one to be retained
egen `maxspell'= max(`seq'), by(`pv')
bysort `pv': generate `keepspell' = cond(`seq'==`maxspell',`spell',0)
egen `wantspell' = max(`keepspell'), by(`pv')
* in case of ties, latest spell of max length is selected
list `pv' `tv' `spell' `seq' `maxspell' `keepspell' `wantspell', sepby(`pv')
summarize `spell' `wantspell'
keep if `wantspell' == `spell'
summarize `pv', meanonly
local n2 = r(N)
drop __*
}
display _n "Observations removed: " `n1'-`n2'
save `saving',`replace'
restore
end
*/
webuse grunfeld, clear
All properties
| key |
content |
| command |
webuse |
| indent |
0 |
| options |
clear |
| parameters |
grunfeld |
|