Svend Juul's solution is short, but requires the creation of almost
1000 variables to handle three years of daily data. A more complicated
solution that generates a long-format dataset in one swell foop:
clear
input admdate discdate
10000 10003
10002 10004
10001 10007
10004 10005
10004 10009
end
g daysin = discdate - admdate + 1
su daysin, meanonly
local npat = r(N)
local nrec = r(sum)
set obs `nrec'
local j 0
g daystay = .
g workload = 1
forv i=1/`npat' {
local a = admdate[`i']
local d = discdate[`i']
forv p=`a'/`d' {
local ++j
qui replace daystay = `p' in `j'/`j'
}
}
collapse (count) workload, by(daystay)
format daystay %td
list
Presumably there is a doctor-ID somewhere in here. That could also be
placed on each of the long-format records so that summarization by
doctor and day could take place in one step.