---------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  C:\Users\jstock\Dropbox\coronavirus\Code\BPEA_replication_code\SEIRD_SEs_v2.txt
  log type:  text
 opened on:  27 Jul 2020, 11:28:01

. set more off 

. set scheme s1color

. pause on

. ************************************************************************************
. * SEIRD_SEs_v3.do                    JS 6/15 - 7/26/20
. *
. * SEs for (calibrate) SEIRD model - R0, predicted deaths
. *   v1: SEs by delta method
. *   v2: plots for different assumed IFRs
. *   v3: clean version for BPEA final draft
. ************************************************************************************
. *
. global outpath "../../Output/Epidemiology/Sheets"

. global figpath "figs/estn"

. 
. * --------- Model parameters ------------
. * latency and contagious periods
. global sigma = exp(1/4.86)-1   // Mean of published studies (Adriano memo)

. global gamma = exp(1/5)-1     // Kissler et al (Science, April 14 2020)

. 
. do NLSEIRD_PID_v12  // SEIRD model with time-varying contact matrices and PID controller, for nl estn

. * Program NLSEIRD_PID
. *  SEIRD simulation with:
. *       time-varying contact matrices
. *       parameter estimation (command nl) over edates
. *       PID controller
. *       Estimation of intensity parameter (phi) for active NPI dates
. *       First date is Feb 21, 2020
. *  v12: Clean version for BPEA final draft
. *
. cap program drop nlseird_pid

. program nlseird_pid
  1.  version 16
  2.  syntax varlist(min=1 max=1) if, at(name)
  3.  local dout: word 1 of `varlist'
  4.  tempname I0 phi0 phi1 phi2 beta
  5.  scalar `I0' = 1000*`at'[1,1]
  6.  scalar `phi0' = `at'[1,2]
  7.  scalar `phi1' = `at'[1,3]
  8.  scalar `phi2' = `at'[1,4]
  9.  scalar `beta' = `at'[1,5]
 10.  mat list `at'
 11.  cap drop phifac et
 12.  gen phifac = 1
 13.  local tt = $nedate2 - 19
 14.  global tt = `tt'
 15.  gen et = _n-19
 16.   replace phifac = `phi0' + `phi1'*cos(_pi*(et+0.5)/`tt') + `phi2'*cos(_pi*2*(et+0.5)/`tt') in 19/$nedate2
>  // introduce measures on March 10 (obs 19)
 17.   replace phifac = normprob(phifac) in 19/$nedate2
 18.    qui su phifac in $nedate3/$nedate3 
 19.     qui replace phifac = r(mean) in $nedate3/l
 20.  *
.  local ndates $ndate_END
 21.  local nage = $nage
 22.  local gamma = $gamma
 23.  local sigma = $sigma
 24.  mat delta = J(`nage',1,0)
 25.  forvalues i = 1/`nage' {
 26.   mat delta[`i',1] = `gamma'*IFR[`i',1]/(1-IFR[`i',1])
 27.  }
 28.  local stepsperday = 10
 29. 
.  local DELTA = 1/`stepsperday'
 30.  mat S = J(`ndates',`nage',0)
 31.  mat E = S
 32.  mat I = S
 33.  mat R = S
 34.  mat D = S
 35.  mat Q = S
 36.  mat Dtot = J(`ndates',1,0)
 37.  mat In1 = `I0'*I00
 38.  mat En1 = 4*In1
 39.  mat Sn1 = Nvec - In1 - En1
 40.  mat Rn1 = J(`nage',1,0)
 41.  mat Dn1 = J(`nage',1,0)
 42.  mat Qn1 = J(`nage',1,0)
 43.  mat r0 = J(`ndates',1,0)
 44.  mat r0_approx = J(`ndates',1,0)
 45.  mat cfacc = J(`ndates',1,1)
 46.  mat maxReval = maxReval_input
 47.  mat lshock = lshock_npi
 48.  *mat lshare = lshare_npi
.  mat gdp = lshock[1...,1..66]*psi
 49.  mat emp0 = J(1,rowsof(emp_count_tot),1)*emp_count_tot
 50.   global emp0 = emp0[1,1]
 51.  mat unrate = J(`ndates',1,1) - lshock[1..`ndates',1...]*emp_count_tot/$emp0
 52.  mat g = J(68,1,0)
 53.  local ndate_PIDm1 = $nedate3
 54.  local ndate_PIDmin = 52 // set worst-case hours to be hours in April Establishment Survey (obs 52 = 12Apr
> 2020)
 55.  forvalues d = 1/`ndates' {
 56.   if $nage==1 {
 57.    mat cmat = maxReval[`d'] // for 1-age model, sequence of NPIs is reduced to scalar
 58.    if npimat[`d',1]<1 {
 59.      mat cmat = `phi0'*cmat
 60.    }
 61.   }
 62.   if $nage>1 {
 63.    if PID[`d',1]==0 {
 64.    * Historical component (for estimation) before controller
.    * today's contact matrix
.     mat cwork = J(5,5,0)
 65.     mat cother = J(5,5,0)
 66.     mat chome = J(5,5,0)
 67.     forvalues a = 1/5 {
 68.      mat cwork[`a',1]  = cmwx`a'[`d']*cnwork_mean[`a',1...] 
 69.          mat cother[`a',1] = cmox`a'[`d']*cother_mean[`a',1...]
 70.      mat chome[`a',1]  = cmhx`a'[`d']*chome_mean[`a',1...]
 71.     }
 72.     mat cmat = ($hHH + (1-$hHH)*phifac[`d'])*chome + phifac[`d']*(cother + cwork)
 73.    }
 74.   }
 75.   if PID[`d',1]==1 {
 76.    * State variables for controller 
.    mat unratem1 = J(1,$dlag,1)*unrate[`d'-$dlag..`d'-1,1]/$dlag // avge unemployment rate over last $dlag day
> s
 77.    mat unratecum = J(1,`d'-1,1)*unrate[1..`d'-1,1] // cumulative unemployment rate (units: pp-days)
 78.    mat dDtot = (Dtot[`d'-1,1]-Dtot[`d'-3,1])/2 // average daily deaths, last 2 days
 79.    mat ddDtot = ( dDtot  - (Dtot[`d'-$dlag-1,1]-Dtot[`d'-$dlag-3,1])/2 )/$dlag
 80.    * Controller
.    mat cfacc[`d',1] = $ku*unratem1 + $kiu*unratecum - $kp*dDtot - $kd*ddDtot
 81.    if `d'==$ndate_PID {
 82.    * compute intercept so employment(t) = employment(t-1) for t first date of controller
.         mat dL   = (lshock[`ndate_PIDm1',1...] - lshock[`ndate_PIDmin',1...])*emp_count_tot
 83.         mat alphabar = cfacc[`d',1] + $k1*(theta_gdp'*J(68,1,1)/68)
 84.         mat xbar = (lshockmax' - lshock[`ndate_PIDmin',1...])*emp_count_tot
 85.         local mu0 = normprob(dL[1,1]/xbar[1,1]) - alphabar[1,1]
 86.         * iterate on intercept using Taylor series first order condition 
.         forvalues kk = 1/5 {
 87.                 local dx0 = 0
 88.                 local dx1 = 0
 89.                 forvalues i = 1/68 {
 90.                         local xi = (lshockmax[`i',1]-lshock[`ndate_PIDmin',`i'])*emp_count_tot[`i',1]
 91.                         local dx0 = `dx0' +  normprob(cfacc[`d',1] + $k1*theta_gdp[`i'] + `mu0')*`xi'
 92.                         local dx1 = `dx1' + normalden(cfacc[`d',1] + $k1*theta_gdp[`i'] + `mu0')*`xi'
 93.                 }
 94.                 local mu0 = `mu0' + (dL[1,1] - `dx0')/`dx1' // shift in controller by sector to equate ini
> tial value of controller to final value of historical on average
 95.         }
 96.         local mu = `mu0'
 97.         }
 98.         mat dlshock = ( (Q[`d'-1,1...]-Q[`d'-2,1...]) + (D[`d'-1,1...]-D[`d'-2,1...]) )*Lvec/N // prior-da
> y net worker flows into being unable to work = Q + D, proportional to epop
 99.         forvalues i = 1/68 {
100.          mat g[`i',1] = normprob( cfacc[`d',1] + $k1*theta_gdp[`i'] + `mu' )
101.      local lsmaxi = 1
102.          forvalues a = 1/5 {
103.           local lsmaxi = `lsmaxi' - (1-wfh_share[`i'])*(1-selage[`a',1])*emp_count`a'[`i']/emp_count_tot[`
> i']
104.      }
105.          local lsmaxi = min(`lsmaxi',lshockmax[`i',1]) // Age-restricted workers work from home in proport
> ion to sector's ability, possibly restricting sectoral employment
106.          mat lshock[`d',`i'] = lshock[`ndate_PIDmin',`i'] + g[`i',1]*(`lsmaxi'-lshock[`ndate_PIDmin',`i'] 
> ) // asymptote to lshock_max employment by sector (taste shift)
107.          mat lshock[`d',`i'] = lshock[`d',`i'] - (dlshock[1,1]/$Ltot)*epop[`i',1]*(N/$Ltot)
108.          if `d'>=186 {  // School opens (or not) on Aug 24
109.           mat lshock[`d',`i'] = min(lshock[`d',`i'],1 - 0.067*(1-school_frac[`d'])) // 6.7% of workers hav
> e childcare obligations Dingel-Patterson-Vavra (April 2020 Table 1)
110.          }
111.         }
112.     mat unrate[`d',1] = 1 - lshock[`d',1...]*emp_count_tot/$emp0
113.         mat gdp[`d',1] = lshock[`d',1..66]*psi
114.     * Construct contact matrices
.     mat cwork=J(5,5,0)
115.     forvalues a = 1/5 {
116.      sca scmwx`a' = 0
117.      forvalues i = 1/68 {
118.       sca scmwx`a' = scmwx`a' + lshock[`d',`i']*(1-wfh_frac[`d']*wfh_share[`i'])*epop`a'[`i']*pp_rel`a'[`i
> ']
119.      }
120.      mat cwork[`a',1] = (phifac[`ndate_PIDm1']+sdwork_fac[`d']*(1-phifac[`ndate_PIDm1']))*selage[`a',1]*sc
> mwx`a'*cnwork_mean[`a',1...] 
121.     }
122.         * Other contacts: 20+ reengage in shopping in proportion to production (supply = demand), with pro
> tections that can be relaxed
.         mat cother_1  =  (phifac[`ndate_PIDm1'] + sdoth_fac1[`d']*(1-phifac[`ndate_PIDm1'])) * ($o1ns + schoo
> l_frac[`d']*(1-$o1ns)) * cother_mean1
123.         mat cother_24 =  (phifac[`ndate_PIDm1'] + sdoth_fac24[`d']*(1-phifac[`ndate_PIDm1'])) ///
>                                    * (gmio[`ndate_PIDm1'] + ((gdp[`d',1]-gdp[`ndate_PIDm1',1])/gdp[1,1])*(gmi
> o[1]-gmio[`ndate_PIDm1'])) * cother_mean24 
124.         mat cother_5  =  (phifac[`ndate_PIDm1'] + sdoth_fac5[`d']*(1-phifac[`ndate_PIDm1'])) ///
>                                    * (gmio[`ndate_PIDm1'] + ((gdp[`d',1]-gdp[`ndate_PIDm1',1])/gdp[1,1])*(gmi
> o[1]-gmio[`ndate_PIDm1'])) * cother_mean5
125.         mat cother = cother_1 + cother_24 + cother_5
126.     mat chome = ( $hHH + (1-$hHH)*(phifac[`ndate_PIDm1']+sdhome_fac[`d']*(1-phifac[`ndate_PIDm1'])) )*chom
> e_mean 
127.         mat chome[5,1] = home_fac5[`d']*chome[5,1...]
128.     mat cmat = chome + cother + cwork
129.   }
130.   if `d'==163 {
131.         mat ctot_Aug1 = cmat
132.   }
133.   if `d'==238 {
134.         mat ctot_Oct15 = cmat
135.   }
136.   mat cmat = hadamard(cmat_adjust_kids,cmat) // adjust for reduced transmission rates to/from/between kids
137.   mat cnormalized = hadamard(cmat,Nvecinv*Nvec')
138.   mat eigenvalues r c = cnormalized
139.   mat maxReval[`d',1] = r[1,1]
140.   mat r0_approx[`d',1] = `beta'*maxReval[`d',1]/`gamma' // version used through v8
141.   mat cnormBetaGamma = J(5,5,0)
142.   forvalues i = 1/5 {
143.    forvalues j = 1/5 {
144.     mat cnormBetaGamma[`i',`j'] = `beta'*cnormalized[`i',`j']/(`gamma' + delta[`j',1])
145.    }
146.   }
147.   mat eigenvalues r c = cnormBetaGamma
148.   mat r0[`d',1] = r[1,1] // correct with age-based delta and beta
149.   forvalues i = 1/`stepsperday' {
150.    mat dQshock = J(`nage',1,0)
151.    * Simulate removal of 1000 infected
.    if (`d'==$ndate_remove)*(`i'==`stepsperday') {
152.     mat dQshock = $nremove*Nvec/N
153.    }
154.    mat dS = -`DELTA'*`beta'*hadamard(Sn1,cmat*hadamard(In1,Nvecinv))
155.    mat dE = -dS - `DELTA'*`sigma'*En1
156.    mat dQ = -`DELTA'*`gamma'*Qn1 - `DELTA'*hadamard(delta,Qn1) + `DELTA'*qrate[`d']*In1 + dQshock
157.    mat dR = `DELTA'*`gamma'*In1 + `DELTA'*`gamma'*Qn1
158.    mat dD = `DELTA'*hadamard(delta,In1) + `DELTA'*hadamard(delta,Qn1)
159.    mat dI = `DELTA'*`sigma'*En1 - `DELTA'*`gamma'*In1 - `DELTA'*hadamard(delta,In1) - `DELTA'*qrate[`d']*I
> n1 - dQshock
160.    mat Sn = Sn1 + dS
161.    mat En = En1 + dE
162.    mat In = In1 + dI
163.    mat Qn = Qn1 + dQ
164.    mat Rn = Rn1 + dR
165.    mat Dn = Dn1 + dD
166.    mat Sn1 = Sn
167.    mat En1 = En
168.    mat In1 = In
169.    mat Qn1 = Qn
170.    mat Rn1 = Rn
171.    mat Dn1 = Dn
172.   }
173.   mat S[`d',1] = Sn'
174.   mat E[`d',1] = En'
175.   mat I[`d',1] = In'
176.   mat Q[`d',1] = Qn'
177.   mat R[`d',1] = Rn' 
178.   mat D[`d',1] = Dn'
179.   mat Dtot[`d',1] = D[`d',1...]*J(5,1,1)
180.  }
181.  foreach m in "S" "E" "I" "Q" "R" "D" {
182.   mat `m'tot = `m'*J(`nage',1,1)
183.  }
184.  mat rr = r0
185.  mat lIdot = 0*r0
186.  forvalues d = 4/`ndates' {
187.   mat rr[`d',1] = 1 + (1/`gamma')*( (Itot[`d',1]-2*Itot[`d'-1,1]+Itot[`d'-1,1])/(Itot[`d',1]-Itot[`d'-2,1]
> ) )
188.  }
189.  * create useful matrices
.  local nm7 = rowsof(D)-7
190.  mat W = D - (J(7,colsof(D),0)\D[1..`nm7',1...]) 
191.  mat reff = hadamard(r0,Stot/N)
192.  mat rreff = hadamard(rr,Stot/N)
193.  mat Dtot = D*J(colsof(D),1,1)
194.  mat Wtot = W*J(colsof(D),1,1)
195.  mat Rtot = R*J(colsof(D),1,1)
196.  global IFR_sim = Dtot[rowsof(Dtot),1]/Rtot[rowsof(Dtot),1]
197.  cap drop Dtot Dtot1
198.  svmat Dtot, names(Dtot)
199.  qui replace Dtot = Dtot1/1000    // all counts in thousands
200.  cap drop Wtot Wtot1
201.  svmat Wtot, names(Wtot)
202.  qui replace Wtot = Wtot1/1000    // all counts in thousands
203.  qui replace `dout' = Wtot `if'  // estimate using weekly deaths
204.  mat gdp = gdp/gdp[1,1]
205.  *
. if $varout==1 {
206.   * optionally, turn model output matrices into Stata variables
.  foreach v in "S" "E" "I" "Q" "R" "D" "W" {
207.    cap drop `v'*
208.    svmat `v', names(`v')
209.    qui gen `v'tot = 0
210.    forvalue i = 1/`nage' {
211.     qui replace `v'`i' = `v'`i'/1000  // save in thousands
212.     qui gen `v'shr`i' = `v'`i'/(Nvec[`i',1]/1000)
213.     qui replace `v'tot = `v'tot + `v'`i'
214.    }
215.    qui gen `v'shrtot = `v'tot/(N/1000)
216.    if `nage'==5 {
217.     foreach w in "" "shr" {
218.      label var `v'`w'1 "<20"
219.      label var `v'`w'2 "20-44"
220.      label var `v'`w'3 "45-64"
221.      label var `v'`w'4 "65-74"
222.      label var `v'`w'5 "75+"
223.      label var `v'`w'tot "All ages"
224.     }
225.    }
226.   }
227.   foreach r in "rr" "r0" "reff" "rreff" "unrate" "gdp" {
228.    cap drop `r'
229.    svmat `r', names(`r')
230.    qui rename `r'1 `r'
231.   }
232.   mat list IFR
233.   dis "gamma " `gamma'
234.   dis "beta " `beta'
235.   dis "sigma " `sigma'
236.   dis "IFR_sim " $IFR_sim
237.  }
238. end

. 
end of do-file

. do NPI_setup_v5

. cd "/Users//`=c(username)'/Dropbox/coronavirus/Code/BPEA_replication_code"
C:\Users\jstock\Dropbox\coronavirus\Code\BPEA_replication_code

. *******************************************************************************
. *  NPI_setup_v5.do                     JS 4/18/20 - 7/6/20
. *
. *  Merger of NPI_construct_v9 and NPI_setup_v2
. *   Structure is for BPEA paper (not NBER WP) with NPIs estimated by TV phi function
. *   With this version this becomes the master data read file which also creates all 
. *   matrices needed for estimation and simulation 
. *   Note somewhat complicated data structure: 
. *     series by industry with no time dimension are obsno 1-68
. *     time series with no industry dimension are by date (21Feb2020 = first obs)
. *     Series with industry and time dimensions are denoted by industry number suffix: lshock`i'
. *  _v5: final draft of BPEA paper (cleaned)
. *******************************************************************************
. *
. * set paths
. global dpath "data-in"

. 
. global nage = 5

. * Contact parameters
. global inf_kids2adults = 0.27 // fraction of beta for transmission, kids to adults (Kong lit review)

. global inf_adults2kids = 0.44 // fraction of beta for transmission, adults to kids (Kong lit review)

. global o1ns = 0.3 // fraction of <20 contacts made while not at school under normal conditions

. global hHH = 0.8 // fraction of home contacts that are household members

. 
. global today: dis %td date(c(current_date),"DMY")

. 
. * -----------------------------------------------------
. *    A. Read in data
. * -----------------------------------------------------
. *     A1. Industry data 
. * -----------------------------------------------------
. * Employment count by sector (total) - aligns with CPS
. import delimited using "$dpath/sector_empshare_bea.csv", case(lower) varn(1) clear
(6 vars, 69 obs)

.  keep in 1/68
(1 observation deleted)

.  gen ncode = _n

.  save tmp1.dta, replace
(note: file tmp1.dta not found)
file tmp1.dta saved

. 
. * Age share breakdown by sector from ACS (note: counts don't add to total CPS count, use these for shares)
. import delimited using "$dpath/sector_age_wfh_profiles_bea_summary_051820.csv", case(lower) varn(1) clear 
(27 vars, 68 obs)

.  keep in 1/68
(0 observations deleted)

.  save tmp2.dta, replace
(note: file tmp2.dta not found)
file tmp2.dta saved

. 
. * Fraction able to work from home (wfw_share - Dingel-Nieman) and fraction with high personal proximity at wo
> rk (pp_share - Mongey-Weinberg)
. import delimited using "$dpath/sector_wfh_profiles_bea_summary_051820.csv", case(lower) varn(1) clear 
(9 vars, 68 obs)

.  gen wfh_share = wfh_share_dn // preferred measure since they checked by hand per Stephanie

.  label var wfh_share "Share of workers who can work at home (Dingel-Nieman)"

.  label var pp_share "Share of workers with high personal proximity at work (Mongey-Weinberg)"

.  save tmp3.dta, replace
(note: file tmp3.dta not found)
file tmp3.dta saved

. 
. * Hours shock from CPS, Feb (benchmark)
. import excel using "$dpath/LaborShock_EPImodel_July2020.xlsx", case(lower) firstrow clear // Feb, March, Apri
> l, May, July
(20 vars, 70 obs)

.  rename epi_code iocode

.  drop if febtomarch_hoursshock ==.
(5 observations deleted)

.  save tmp4.dta, replace
(note: file tmp4.dta not found)
file tmp4.dta saved

.  
. * Labor income share data
. import excel using "$dpath/labor_income_share.xlsx", firstrow case(lower) clear
(2 vars, 66 obs)

.  save tmp5.dta, replace
(note: file tmp5.dta not found)
file tmp5.dta saved

. 
. * -----------------------------------------------------
. *     A2. Time series data
. * -----------------------------------------------------
. * Google mobility data and school closure data
. * update: https://www.google.com/covid19/mobility/
. use "$dpath/Google mobility indicators_US", clear

.  format date %td

.  tsset date
        time variable:  date, 15feb2020 to 17jul2020
                delta:  1 day

.  gen gmio = (retail_and_recreation_percent_ch + transit_stations_percent_change_ + grocery_and_pharmacy_perce
> nt_cha)/3

.  gen gmiw = workplaces_percent_change_from_b 

.   qui replace gmiw = gmiw[_n+1] if tin(25May2020,25May2020) // smooth over Memorial day spike

.  foreach vv in "gmio" "gmiw" {
  2.   qui replace `vv' = 1 + `vv'/100
  3.   tssmooth ma `vv'_sm = `vv', window(3 1 3)
  4.   su `vv'_sm if tin(21Feb2020,29Feb2020)
  5.   qui replace `vv'_sm = `vv'_sm/r(mean)
  6.   qui replace `vv' = `vv'/r(mean)
  7.  }
The smoother applied was
     (1/7)*[x(t-3) + x(t-2) + x(t-1) + 1*x(t) + x(t+1) + x(t+2) + x(t+3)]; x(t)= gmio

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
     gmio_sm |          9    1.039894    .0163105   1.018571   1.065238
The smoother applied was
     (1/7)*[x(t-3) + x(t-2) + x(t-1) + 1*x(t) + x(t+1) + x(t+2) + x(t+3)]; x(t)= gmiw

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
     gmiw_sm |          9    1.021905    .0042857   1.014286   1.025714

.  keep if tin(21Feb2020,)
(6 observations deleted)

.  global t0_gmi = string(day(date[_N-3])) + "/" + string(month(date[_N-3])) + "/" + string(year(date[_N-3]))

.  keep if tin(,$t0_gmi)
(3 observations deleted)

.  *
.  * School closure data (Source: \Data\Clean\Epi|SchoolClosures.xlsx has data and documentation)
.  gen school_frac = 1

.   qui replace school_frac = .6548 if tin(16Mar2020,16Mar2020)

.   qui replace school_frac = .4880 if tin(17Mar2020,17Mar2020)

.   qui replace school_frac = .3255 if tin(18Mar2020,18Mar2020)

.   qui replace school_frac = .0707 if tin(19Mar2020,19Mar2020)

.   qui replace school_frac = .0301 if tin(20Mar2020,22Mar2020)

.   qui replace school_frac = .0059 if tin(23Mar2020,23Mar2020)

.   qui replace school_frac = 0 if tin(24Mar2020,)

. *
.  save tmp_t1, replace
(note: file tmp_t1.dta not found)
file tmp_t1.dta saved

. 
.  * -------- JHU deaths data ----------------
. use "$dpath/JHU_data_us", clear

. gen deaths_thou = deaths/1000  // Units of SEIRD output are thousands

. gen confirmed_thou = confirmed/1000    // Units of SEIRD output are thousands

. label var deaths_thou "Deaths (actual, thous)"

.  label var confirmed_thou "Confirmed cases (actual, thous)"

. format date %td

. tsset date
        time variable:  date, 22jan2020 to 21jul2020
                delta:  1 day

. keep if tin(21Feb2020,)
(30 observations deleted)

. cap drop deaths_weekly

. gen deaths_weekly = deaths_thou - L7.deaths_thou
(7 missing values generated)

.    label var deaths_weekly "Weekly deaths, actual (thou)"

. gen deaths_daily = deaths_thou - L.deaths_thou
(1 missing value generated)

.    label var deaths_daily "Daily deaths, actual (thou)"

. list date deaths deaths_daily deaths_weekly

     +-------------------------------------------+
     |      date    deaths   deat~ily   deat~kly |
     |-------------------------------------------|
  1. | 21feb2020         0          .          . |
  2. | 22feb2020         0          0          . |
  3. | 23feb2020         0          0          . |
  4. | 24feb2020         0          0          . |
  5. | 25feb2020         0          0          . |
     |-------------------------------------------|
  6. | 26feb2020         0          0          . |
  7. | 27feb2020         0          0          . |
  8. | 28feb2020         0          0          0 |
  9. | 29feb2020         1       .001       .001 |
 10. | 01mar2020         1          0       .001 |
     |-------------------------------------------|
 11. | 02mar2020         6       .005       .006 |
 12. | 03mar2020         7       .001       .007 |
 13. | 04mar2020        11       .004       .011 |
 14. | 05mar2020        12       .001       .012 |
 15. | 06mar2020        14       .002       .014 |
     |-------------------------------------------|
 16. | 07mar2020        17       .003       .016 |
 17. | 08mar2020        21       .004        .02 |
 18. | 09mar2020        22       .001       .016 |
 19. | 10mar2020   28.1344   .0061344   .0211344 |
 20. | 11mar2020   33.1344       .005   .0221344 |
     |-------------------------------------------|
 21. | 12mar2020   43.1344        .01   .0311344 |
 22. | 13mar2020   52.1344       .009   .0381344 |
 23. | 14mar2020   58.1344       .006   .0411344 |
 24. | 15mar2020   70.2687   .0121344   .0492687 |
 25. | 16mar2020   97.2687       .027   .0752687 |
     |-------------------------------------------|
 26. | 17mar2020   131.403   .0341344   .1032687 |
 27. | 18mar2020   188.672   .0572687   .1555375 |
 28. | 19mar2020   266.209   .0775374   .2230749 |
 29. | 20mar2020   363.478   .0972687   .3113436 |
 30. | 21mar2020    458.15   .0946718   .4000154 |
     |-------------------------------------------|
 31. | 22mar2020   603.687   .1455375   .5334185 |
 32. | 23mar2020   787.628   .1839405   .6903591 |
 33. | 24mar2020   1026.91   .2392842   .8955089 |
 34. | 25mar2020   1341.33   .3144186   1.152659 |
 35. | 26mar2020   1756.88    .415553   1.490674 |
     |-------------------------------------------|
 36. | 27mar2020   2314.51   .5576278   1.951033 |
 37. | 28mar2020   2952.81   .6382997   2.494661 |
 38. | 29mar2020   3582.63   .6298215   2.978945 |
 39. | 30mar2020    4407.6   .8249717   3.619977 |
 40. | 31mar2020   5640.88   1.233271   4.613963 |
     |-------------------------------------------|
 41. | 01apr2020    6893.7   1.252824   5.552369 |
 42. | 02apr2020   8504.15   1.610454    6.74727 |
 43. | 03apr2020    9833.8   1.329646   7.519288 |
 44. | 04apr2020   11144.7   1.310873   8.191861 |
 45. | 05apr2020   12593.2    1.44854    9.01058 |
     |-------------------------------------------|
 46. | 06apr2020   14272.8   1.679555   9.865163 |
 47. | 07apr2020   16612.5    2.33977   10.97166 |
 48. | 08apr2020   18765.1   2.152546   11.87138 |
 49. | 09apr2020   20867.6   2.102545   12.36347 |
 50. | 10apr2020   22990.6   2.122963   13.15679 |
     |-------------------------------------------|
 51. | 11apr2020   25070.3   2.079725   13.92564 |
 52. | 12apr2020   26863.8    1.79344   14.27054 |
 53. | 13apr2020   28704.3   1.840496   14.43149 |
 54. | 14apr2020   31156.9   2.452639   14.54435 |
 55. | 15apr2020   33753.1   2.596161   14.98797 |
     |-------------------------------------------|
 56. | 16apr2020   35914.7    2.16164   15.04706 |
 57. | 17apr2020     38572   2.657265   15.58137 |
 58. | 18apr2020   40988.9   2.416904   15.91854 |
 59. | 19apr2020   42257.1   1.268234   15.39334 |
 60. | 20apr2020   44070.1   1.813007   15.36585 |
     |-------------------------------------------|
 61. | 21apr2020   46561.6   2.491531   15.40474 |
 62. | 22apr2020     49004   2.442341   15.25092 |
 63. | 23apr2020   51478.1   2.474083   15.56337 |
 64. | 24apr2020   53630.6   2.152534   15.05864 |
 65. | 25apr2020   55311.6   1.681038   14.32277 |
     |-------------------------------------------|
 66. | 26apr2020   56607.9   1.296223   14.35076 |
 67. | 27apr2020   58047.1   1.439243   13.97699 |
 68. | 28apr2020   60319.6   2.272476   13.75794 |
 69. | 29apr2020   62869.8   2.550209   13.86581 |
 70. | 30apr2020   65227.2   2.357399   13.74912 |
     |-------------------------------------------|
 71. | 01may2020   67137.8    1.91066   13.50725 |
 72. | 02may2020   68721.2   1.583405   13.40961 |
 73. | 03may2020   69834.6   1.113335   13.22673 |
 74. | 04may2020   71148.8    1.31424   13.10172 |
 75. | 05may2020   73500.7   2.351883   13.18113 |
     |-------------------------------------------|
 76. | 06may2020   75999.7   2.498978    13.1299 |
 77. | 07may2020   77953.3   1.953667   12.72617 |
 78. | 08may2020   79700.9   1.747559   12.56306 |
 79. | 09may2020   81200.9   1.499962   12.47962 |
 80. | 10may2020   82098.7   .8978119    12.2641 |
     |-------------------------------------------|
 81. | 11may2020     83123   1.024284   11.97414 |
 82. | 12may2020   84763.6   1.640663   11.26292 |
 83. | 13may2020   86539.2   1.775589   10.53954 |
 84. | 14may2020   88344.4   1.805168   10.39104 |
 85. | 15may2020   90032.5   1.688141   10.33162 |
     |-------------------------------------------|
 86. | 16may2020   91270.7   1.238182   10.06984 |
 87. | 17may2020   92036.4   .7657089   9.937737 |
 88. | 18may2020   92816.6   .7802124   9.693665 |
 89. | 19may2020   94387.5   1.570885   9.623886 |
 90. | 20may2020   95977.3   1.589767   9.438065 |
     |-------------------------------------------|
 91. | 21may2020   97213.3   1.236031   8.868927 |
 92. | 22may2020     98501   1.287682   8.468468 |
 93. | 23may2020     99635   1.134033   8.364319 |
 94. | 24may2020    100251   .6155243   8.214134 |
 95. | 25may2020    100765   .5142059   7.948128 |
     |-------------------------------------------|
 96. | 26may2020    101456   .6913147   7.068558 |
 97. | 27may2020    102985   1.528488   7.007278 |
 98. | 28may2020    104176   1.191399   6.962646 |
 99. | 29may2020    105358   1.182396   6.857361 |
100. | 30may2020    106341   .9828415   6.706169 |
     |-------------------------------------------|
101. | 31may2020    106936   .5945969   6.685242 |
102. | 01jun2020    107711   .7753601   6.946396 |
103. | 02jun2020    108751   1.039452   7.294533 |
104. | 03jun2020    109755   1.004646   6.770691 |
105. | 04jun2020    110776   1.021088    6.60038 |
     |-------------------------------------------|
106. | 05jun2020    111757   .9806137   6.398598 |
107. | 06jun2020    112445   .6876602   6.103416 |
108. | 07jun2020    112905   .4604034   5.969223 |
109. | 08jun2020    113415   .5101089   5.703972 |
110. | 09jun2020    114367   .9519577   5.616478 |
     |-------------------------------------------|
111. | 10jun2020    115294   .9269409   5.538773 |
112. | 11jun2020    116184   .8898697   5.407555 |
113. | 12jun2020    117012   .8281784   5.255119 |
114. | 13jun2020    117780   .7677383   5.335197 |
115. | 14jun2020    118083   .3031082   5.177902 |
     |-------------------------------------------|
116. | 15jun2020    118480    .397583   5.065376 |
117. | 16jun2020    119331   .8502884   4.963707 |
118. | 17jun2020    120088   .7567749   4.793541 |
119. | 18jun2020    120796   .7085724   4.612244 |
120. | 19jun2020    121473   .6764297   4.460495 |
     |-------------------------------------------|
121. | 20jun2020    122086   .6129608   4.305717 |
122. | 21jun2020    122343   .2570114   4.259621 |
123. | 22jun2020    122753   .4107056   4.272743 |
124. | 23jun2020    123597   .8438492   4.266304 |
125. | 24jun2020    124361    .763855   4.273384 |
     |-------------------------------------------|
126. | 25jun2020    125026   .6650543   4.229866 |
127. | 26jun2020    125631   .6049957   4.158432 |
128. | 27jun2020    126120    .489006   4.034477 |
129. | 28jun2020    126361   .2409973   4.018463 |
130. | 29jun2020    126711   .3499985   3.957756 |
     |-------------------------------------------|
131. | 30jun2020    127432   .7210007   3.834908 |
132. | 01jul2020    128105   .6729965   3.744049 |
133. | 02jul2020    128803    .697998   3.776993 |
134. | 03jul2020    129442   .6390076   3.811005 |
135. | 04jul2020    129689    .246994   3.568993 |
     |-------------------------------------------|
136. | 05jul2020    129960   .2710114   3.599007 |
137. | 06jul2020    130285   .3249969   3.574005 |
138. | 07jul2020    131480   1.194992   4.047997 |
139. | 08jul2020    132300   .8200073   4.195007 |
140. | 09jul2020    133290   .9899902      4.487 |
     |-------------------------------------------|
141. | 10jul2020    134101   .8110046   4.658997 |
142. | 11jul2020    134777   .6759949   5.087997 |
143. | 12jul2020    135205    .428009   5.244995 |
144. | 13jul2020    135566   .3609924   5.280991 |
145. | 14jul2020    136466   .9000092   4.986008 |
     |-------------------------------------------|
146. | 15jul2020    137415   .9489899    5.11499 |
147. | 16jul2020    138358   .9430084   5.068008 |
148. | 17jul2020    139266   .9080048   5.165009 |
149. | 18jul2020    140119   .8529968    5.34201 |
150. | 19jul2020    140534   .4149933   5.328995 |
     |-------------------------------------------|
151. | 20jul2020    140913   .3789978      5.347 |
152. | 21jul2020    141995   1.082001   5.528992 |
     +-------------------------------------------+

. gen ldeaths_weekly = ln(deaths_weekly)
(8 missing values generated)

. global t0_deaths = string(day(date[_N])) + "/" + string(month(date[_N])) + "/" + string(year(date[_N]))

. save tmp_t2.dta, replace
(note: file tmp_t2.dta not found)
file tmp_t2.dta saved

.  
. * -----------------------------------------------------
. *     A3. Merge
. * -----------------------------------------------------
. * First merge industry data by iocode
. use tmp1, clear

.  erase tmp1.dta

. forvalues i = 2/5 {
  2.  merge 1:1 iocode using tmp`i'
  3.  drop _merge
  4.  erase tmp`i'.dta
  5. }

    Result                           # of obs.
    -----------------------------------------
    not matched                             0
    matched                                68  (_merge==3)
    -----------------------------------------
(note: variable emp_count was long, now double to accommodate using data's values)
(note: variable pop was float, now double to accommodate using data's values)

    Result                           # of obs.
    -----------------------------------------
    not matched                             0
    matched                                68  (_merge==3)
    -----------------------------------------

    Result                           # of obs.
    -----------------------------------------
    not matched                             3
        from master                         3  (_merge==1)
        from using                          0  (_merge==2)

    matched                                65  (_merge==3)
    -----------------------------------------

    Result                           # of obs.
    -----------------------------------------
    not matched                             2
        from master                         2  (_merge==1)
        from using                          0  (_merge==2)

    matched                                66  (_merge==3)
    -----------------------------------------

. sort ncode

. list iocode iocode_name

     +--------------------------------------------------------------------+
     | iocode                                                 iocode_name |
     |--------------------------------------------------------------------|
  1. |  111CA                                                       Farms |
  2. |  113FF                         Forestry, fishing, and related atvs |
  3. |    211                                      Oil and gas extraction |
  4. |    212                                     Mining, exc oil and gas |
  5. |    213                                     Support atvs for mining |
     |--------------------------------------------------------------------|
  6. |     22                                                   Utilities |
  7. |     23                                                Construction |
  8. |    321                                               Wood products |
  9. |    327                                Nonmetallic mineral products |
 10. |    331                                              Primary metals |
     |--------------------------------------------------------------------|
 11. |    332                                   Fabricated metal products |
 12. |    333                                                   Machinery |
 13. |    334                            Computer and electronic products |
 14. |    335            Electrical equipment, appliances, and components |
 15. | 3361MV              Motor vehicles, bodies and trailers, and parts |
     |--------------------------------------------------------------------|
 16. | 3364OT                              Other transportation equipment |
 17. |    337                              Furniture and related products |
 18. |    339                                          Misc manufacturing |
 19. |  311FT                      Food and beverage and tobacco products |
 20. |  313TT                     Textile mills and textile product mills |
     |--------------------------------------------------------------------|
 21. |  315AL                     Apparel and leather and allied products |
 22. |    322                                              Paper products |
 23. |    323                           Printing and related support atvs |
 24. |    324                                 Petroleum and coal products |
 25. |    325                                           Chemical products |
     |--------------------------------------------------------------------|
 26. |    326                                Plastics and rubber products |
 27. |     42                                             Wholesale trade |
 28. |    441                             Motor vehicle and parts dealers |
 29. |    445                                    Food and beverage stores |
 30. |    452                                  General merchandise stores |
     |--------------------------------------------------------------------|
 31. |    4A0                                                Other retail |
 32. |    481                                          Air transportation |
 33. |    482                                         Rail transportation |
 34. |    483                                        Water transportation |
 35. |    484                                        Truck transportation |
     |--------------------------------------------------------------------|
 36. |    485                 Transit and ground passenger transportation |
 37. |    486                                     Pipeline transportation |
 38. |  487OS                       Other transportation and support atvs |
 39. |    493                                     Warehousing and storage |
 40. |    511           Publishing inds, exc internet (includes software) |
     |--------------------------------------------------------------------|
 41. |    512                     Motion picture and sound recording inds |
 42. |    513                         Broadcasting and telecommunications |
 43. |    514   Data processing, internet publishing, and other info svcs |
 44. |  521CI    Federal Reserve banks, credit intermed, and related atvs |
 45. |    523            Securities, commodity contracts, and investments |
     |--------------------------------------------------------------------|
 46. |    524                         Insurance carriers and related atvs |
 47. |    525                 Funds, trusts, and other financial vehicles |
 48. |     HS                                                     Housing |
 49. |    ORE                                           Other real estate |
 50. |  532RL             Rental and leasing svcs, lessors of intangibles |
     |--------------------------------------------------------------------|
 51. |   5411                                                  Legal svcs |
 52. |   5415                    Computer systems design and related svcs |
 53. | 5412OP           Misc professional, scientific, and technical svcs |
 54. |     55                           Mgmt of companies and enterprises |
 55. |    561                             Administrative and support svcs |
     |--------------------------------------------------------------------|
 56. |    562                             Waste mgmt and remediation svcs |
 57. |     61                                            Educational svcs |
 58. |    621                                 Ambulatory health care svcs |
 59. |    622                                                   Hospitals |
 60. |    623                     Nursing and residential care facilities |
     |--------------------------------------------------------------------|
 61. |    624                                           Social assistance |
 62. |  711AS          Performing arts, sports, museums, and related atvs |
 63. |    713                   Amusements, gambling, and recreation inds |
 64. |    721                                               Accommodation |
 65. |    722                               Food svcs and drinking places |
     |--------------------------------------------------------------------|
 66. |     81                                       Other svcs, exc govmt |
 67. |    Gov                                                             |
 68. |    GFE                                   Federal govmt enterprises |
     +--------------------------------------------------------------------+

. list ncode iocode labor_income_share

     +----------------------------+
     | ncode   iocode   labor_i~e |
     |----------------------------|
  1. |     1    111CA    .0018641 |
  2. |     2    113FF    .0018363 |
  3. |     3      211    .0033428 |
  4. |     4      212    .0010862 |
  5. |     5      213    .0034191 |
     |----------------------------|
  6. |     6       22      .00724 |
  7. |     7       23     .029967 |
  8. |     8      321    .0012826 |
  9. |     9      327     .001714 |
 10. |    10      331    .0032684 |
     |----------------------------|
 11. |    11      332    .0053409 |
 12. |    12      333    .0062271 |
 13. |    13      334    .0064486 |
 14. |    14      335    .0020705 |
 15. |    15   3361MV    .0046298 |
     |----------------------------|
 16. |    16   3364OT    .0033179 |
 17. |    17      337    .0012197 |
 18. |    18      339    .0033819 |
 19. |    19    311FT    .0065541 |
 20. |    20    313TT   .00071062 |
     |----------------------------|
 21. |    21    315AL    .0007177 |
 22. |    22      322    .0016545 |
 23. |    23      323    .0010761 |
 24. |    24      324    .0010615 |
 25. |    25      325    .0059797 |
     |----------------------------|
 26. |    26      326    .0025929 |
 27. |    27       42      .03648 |
 28. |    28      441    .0058449 |
 29. |    29      445    .0056489 |
 30. |    30      452     .006746 |
     |----------------------------|
 31. |    31      4A0     .020479 |
 32. |    32      481    .0035314 |
 33. |    33      482    .0014429 |
 34. |    34      483   .00045434 |
 35. |    35      484    .0058077 |
     |----------------------------|
 36. |    36      485    .0013826 |
 37. |    37      486   .00049995 |
 38. |    38    487OS    .0059485 |
 39. |    39      493    .0031489 |
 40. |    40      511    .0053647 |
     |----------------------------|
 41. |    41      512    .0021312 |
 42. |    42      513    .0060902 |
 43. |    43      514    .0024742 |
 44. |    44    521CI     .013571 |
 45. |    45      523     .016615 |
     |----------------------------|
 46. |    46      524     .017565 |
 47. |    47      525   .00008723 |
 48. |    48       HS    .0012503 |
 49. |    49      ORE    .0058768 |
 50. |    50    532RL    .0030184 |
     |----------------------------|
 51. |    51     5411    .0084171 |
 52. |    52     5415     .018282 |
 53. |    53   5412OP     .048501 |
 54. |    54       55     .020155 |
 55. |    55      561     .024084 |
     |----------------------------|
 56. |    56      562    .0017229 |
 57. |    57       61     .013394 |
 58. |    58      621     .031474 |
 59. |    59      622     .028543 |
 60. |    60      623     .008073 |
     |----------------------------|
 61. |    61      624    .0065447 |
 62. |    62    711AS    .0031702 |
 63. |    63      713    .0041999 |
 64. |    64      721    .0040805 |
 65. |    65      722     .020761 |
     |----------------------------|
 66. |    66       81     .023819 |
 67. |    67      Gov           . |
 68. |    68      GFE           . |
     +----------------------------+

. * Merge time series data by date
. gen date = d(21Feb2020)+_n-1

. sort date

. format date %td

. tsset date
        time variable:  date, 21feb2020 to 28apr2020
                delta:  1 day

. tsappend, last(01Jan2021) tsfmt(td)

. forvalues i = 1/2 {
  2.  merge 1:1 date using tmp_t`i'
  3.  drop _merge
  4.  erase tmp_t`i'.dta
  5. }

    Result                           # of obs.
    -----------------------------------------
    not matched                           171
        from master                       171  (_merge==1)
        from using                          0  (_merge==2)

    matched                               145  (_merge==3)
    -----------------------------------------

    Result                           # of obs.
    -----------------------------------------
    not matched                           164
        from master                       164  (_merge==1)
        from using                          0  (_merge==2)

    matched                               152  (_merge==3)
    -----------------------------------------

. gen day = day(date)

. gen month = month(date)

. gen quarter = quarter(date)

. gen year = year(date)

. gen yrmo = 100*(year-2000) + month

. gen yrq = 10*(year-2000) + quarter

. global ndates_tot = _N

. 
. * ----------------------------------------------------------------------------- 
. *    B. Renaming, recoding, create some variables, interpolation, normalizations 
. * ----------------------------------------------------------------------------- 
. gen obsno = _n

. local nind = 66 // industries in IO model = covered industries

. 
. * Sectoral Shock time series
. *   Sectoral hours shocks are pinned down on 12th of month from Establishment Survey data, interpolated using
>  excess new claims
. foreach y of varlist febtomarch_hoursshock marchtoapril_hoursshock apriltomay_hoursshock maytojune_hoursshock
>  {
  2.  qui replace `y' = 0 if iocode=="111CA"
  3.  qui replace `y' = 0 in 67/68
  4. }

. gen shock_Marchhrs = (1+febtomarch_hoursshock)
(248 missing values generated)

. gen shock_Aprilhrs = shock_Marchhrs*(1+marchtoapril_hoursshock)
(248 missing values generated)

. gen shock_Mayhrs = shock_Aprilhrs*(1+apriltomay_hoursshock)
(248 missing values generated)

. gen shock_Junhrs = shock_Mayhrs*(1+maytojune_hoursshock)
(248 missing values generated)

. cap drop y99

. gen y99 = .
(316 missing values generated)

. forvalues i = 1/66 {
  2.  qui replace y99 = .
  3.  qui replace y99 = shock_Marchhrs[`i'] if tin(12Mar2020,12Mar2020)
  4.  qui replace y99 = shock_Aprilhrs[`i'] if tin(12Apr2020,12Apr2020)
  5.  qui replace y99 = shock_Mayhrs[`i'] if tin(12May2020,12May2020)
  6.  qui replace y99 = shock_Junhrs[`i'] if tin(12Jun2020,12Jun2020)
  7.  qui ipolate y99 gmiw_sm, gen(labor_shock`i') e
  8.  qui su labor_shock`i' if tin($t0_gmi,$t0_gmi)
  9.  qui replace labor_shock`i' = r(mean) if tin($t0_gmi,)
 10.  qui replace labor_shock`i' = 1 if tin(,08Mar2020)
 11. }

. gen labor_shock67 = 1

. gen labor_shock68 = 1

. 
. * population shares of covered and noncovered workers by age
. *   CPS employment = 158.759m Feb 2020
. *   CPS LF = 164.546m Feb 2020
. *   Establishment total priv emp = 129.740m Feb 2020
. sca N = 328.2e6 // US population

. mat Nvec = (0.256\0.334\0.261\0.086\0.063)*N

. mat Nvecinv = J(5,1,0)

. forvalues a = 1/5 {
  2.  mat Nvecinv[`a',1] = 1/Nvec[`a',1]
  3. }

. 
. * Baseline employment shares by age/industry.
. * Note need to make adjustment, employment counts by age don't add to total employment count because of BEA/B
> LS counting discrepency
. *  Totals will be BLS values 
. rename emp_count emp_count_tot

. gen epop = emp_count_tot/N // baseline employment-population ratio by industry
(248 missing values generated)

. gen emp_count_tot_unadj = emp_count1 + emp_count2 + emp_count3 + emp_count4 + emp_count5
(248 missing values generated)

. forvalues a = 1/5 {
  2.  rename emp_count`a' emp_count`a'_unadj
  3.  gen emp_count`a' = emp_count_tot*(emp_count`a'_unadj/emp_count_tot_unadj)  // estimated employment by ind
> ustry by age, adjusted for BEA/BLS counting discrepancy
  4.  gen epop`a' = emp_count`a'/Nvec[`a',1]  // employment-population ratio WITHIN each age group (fraction of
>  all 30 yr olds who work in given industry)
  5. }
(248 missing values generated)
(248 missing values generated)
(248 missing values generated)
(248 missing values generated)
(248 missing values generated)
(248 missing values generated)
(248 missing values generated)
(248 missing values generated)
(248 missing values generated)
(248 missing values generated)

. 
. * Relative personal proximity measure - normalize so that wtd averages by age group = 1
. forvalues a = 1/5 {
  2.  cap drop x99
  3.  qui gen x99 = pp_share*epop`a'
  4.  qui su x99
  5.   local wm = r(mean)
  6.  qui su epop`a'
  7.  qui gen pp_rel`a' = pp_share*r(mean)/(`wm'+1e-20)
  8. }

. 
. * wfh time series
. *    Bick, Blandin, and Mertens (June 2020): in Feb 2020 8.2% worked from home, in May 35.2% worked from home
> . 
. mkmat wfh_share in 1/68, mat(wfh_share)

. mkmat emp_count_tot in 1/68, mat(emp_count_tot)

. mat wfh_count = wfh_share'*emp_count_tot

. mat Ltot = emp_count_tot'*J(rowsof(emp_count_tot),1,1)

.  global Ltot = Ltot[1,1]

. global wfh_share_max = wfh_count[1,1]/Ltot[1,1]

. dis wfh_count[1,1] "  " Ltot[1,1] "  " $wfh_share_max
55787773  1.561e+08  .35741379

. gen w99 = .
(316 missing values generated)

.  qui replace w99 = 0.082/$wfh_share_max if tin(21Feb2020,21Feb2020) // BBM estimate

.  qui replace w99 = 0.352/$wfh_share_max if tin(21May2020,21May2020) // BBM estimate

. ipolate w99 gmiw_sm, gen(wfh_frac) e
(171 missing values generated)

. 
. ***************************************************************************
. *          NPI weights
. ***************************************************************************
. * Construct NPI time series weightws by date
. *  There are no good data on fraction of home contacts that are non-HH members. Dorelien et al (2020) Fig 2, 
> 3 suggestion ~85% are HH members (ATUS) 
. *  However, their mean number of total home contacts is ~2 for 20-54 while POLYMOD is 3.7, so 2/3.7 = 0.54. D
> orelian et al is 
. *  especially low at young ages which suggests they are missing play dates from their ATUS calculations.
. *  Absent good data, assume provisionally that 80% of home contacts are HH members. For the non-HH 20%, assum
> e proportionality to gmio, scaled
. 
. gen school_fac = $o1ns + (1-$o1ns)*school_frac // Other activity contact factor for <20, non-school + school
(171 missing values generated)

. su gmio_sm, d

                ma: x(t)= gmio: window(3 1 3)
-------------------------------------------------------------
      Percentiles      Smallest
 1%     .5884298       .5879719
 5%     .6039992       .5884298
10%      .616363       .5930091       Obs                 145
25%     .6690242        .593467       Sum of Wgt.         145

50%     .7821309                      Mean           .7778138
                        Largest       Std. Dev.      .1283931
75%     .8270073       1.024372
90%     1.005139       1.024372       Variance       .0164848
95%     1.018877       1.026203       Skewness       .4355602
99%     1.026203       1.027119       Kurtosis       2.359857

.  gen gmio_sm_scaled = (gmio_sm-r(min))/(r(max)-r(min))
(171 missing values generated)

. 
. forvalues a = 1/5 {
  2.   gen cmox`a' = gmio_sm
  3.   gen cmhx`a' = 1
  4.   gen cmwx`a' = 0
  5.   forvalues i = 1/68 {
  6.    qui replace cmwx`a' = cmwx`a' + labor_shock`i'*(1-wfh_frac*wfh_share[`i'])*epop`a'[`i']*pp_rel`a'[`i']
  7.   }
  8.  }
(171 missing values generated)
(171 missing values generated)
(171 missing values generated)
(171 missing values generated)
(171 missing values generated)

. qui replace cmox1 = gmio_sm*school_fac

. 
. list epop4 epop5 pp_rel4 pp_rel5 cmwx4 cmwx5 in 1/70

     +-----------------------------------------------------------------+
     |    epop4      epop5    pp_rel4    pp_rel5      cmwx4      cmwx5 |
     |-----------------------------------------------------------------|
  1. | .0043669   .0019193   .1336124   .1335876   .2437754   .0617816 |
  2. | .0005829   .0001719   .4517565   .4516728   .2442619    .061902 |
  3. | .0001244    .000024   .2922229   .2921687   .2445051   .0619622 |
  4. | .0002689   .0000456   .4460433   .4459606   .2449916   .0620826 |
  5. | .0004545   .0001513   .5517598   .5516576    .245478   .0622029 |
     |-----------------------------------------------------------------|
  6. | .0015289   .0002361   .6235003   .6233847    .245478   .0622029 |
  7. |  .012109   .0027041   1.230831   1.230603   .2457212   .0622631 |
  8. | .0006837   .0001643   .5486656   .5485639   .2457212   .0622631 |
  9. | .0005796   .0001148   .4726754   .4725878   .2457212   .0622631 |
 10. | .0006487   .0001087   .5035319   .5034386   .2459645   .0623233 |
     |-----------------------------------------------------------------|
 11. | .0022365   .0004132   .3955209   .3954476   .2462077   .0623835 |
 12. | .0019197   .0003932   .5091845   .5090901   .2462077   .0623835 |
 13. | .0016305   .0002716   .2358325   .2357887   .2464509   .0624437 |
 14. | .0005601   .0000802   .3970081   .3969345   .2462077   .0623835 |
 15. | .0011652   .0001367   .7447268   .7445887    .245478   .0622029 |
     |-----------------------------------------------------------------|
 16. | .0011175   .0001999   .4007417   .4006674   .2445051   .0619622 |
 17. | .0006365   .0000932   .5880128   .5879039   .2435322   .0617214 |
 18. | .0024239   .0005579     .52934   .5292419   .2411335   .0610769 |
 19. | .0023376   .0004653   .6576641   .6575422   .2378669   .0602549 |
 20. | .0005615     .00012    .365079   .3650114   .2356993   .0597094 |
     |-----------------------------------------------------------------|
 21. | .0004322   .0000952   .2409675   .2409229   .2324629    .058895 |
 22. | .0005102   .0000753    .464838   .4647519   .2253362   .0571017 |
 23. | .0009952   .0002318   .2670355    .266986   .2165541   .0548919 |
 24. | .0001607     .00003   .3185358   .3184767   .2062009   .0522869 |
 25. | .0014704   .0001921   .3174216   .3173628   .1960497   .0497329 |
     |-----------------------------------------------------------------|
 26. | .0007683   .0001039   .5250326   .5249354    .186429   .0473124 |
 27. | .0075966    .001755   .4274968   .4274176   .1789331   .0454267 |
 28. | .0041375   .0012236   1.092975   1.092773   .1712162   .0434837 |
 29. | .0049977   .0015646   1.926371   1.926014   .1641374   .0416679 |
 30. | .0050628   .0015548   1.905908   1.905555   .1581545   .0401334 |
     |-----------------------------------------------------------------|
 31. | .0166759   .0048088   1.680298   1.679987   .1532283   .0388701 |
 32. | .0008638   .0001166   1.432052   1.431786   .1487966   .0377379 |
 33. |  .000189   .0000158    .484319   .4842292   .1458037   .0369789 |
 34. | .0001305   .0000244   1.255678   1.255445   .1428258   .0362239 |
 35. | .0032442   .0005551   .1874953   .1874606   .1407502   .0356978 |
     |-----------------------------------------------------------------|
 36. | .0032654   .0007357   1.801211   1.800877   .1386818   .0351736 |
 37. | .0000914   .0000117   .5766841   .5765772   .1375031   .0348749 |
 38. | .0017472   .0003352   .6454034   .6452838   .1366207   .0346513 |
 39. | .0005057   .0001018   .9962001   .9960155   .1357396   .0344281 |
 40. | .0011653   .0004587   .2843541   .2843014   .1345669    .034131 |
     |-----------------------------------------------------------------|
 41. |  .000526   .0001124   .6952342   .6951053   .1336889   .0339087 |
 42. | .0013032    .000151   .3088889   .3088317   .1331044   .0337606 |
 43. | .0011836   .0003542    .411063   .4109869   .1325204   .0336127 |
 44. | .0033067   .0007121    .427091   .4270119    .131937    .033465 |
 45. |  .001147   .0002702   .1189384   .1189163   .1313543   .0333174 |
     |-----------------------------------------------------------------|
 46. | .0051348   .0012952   .1172468   .1172251   .1307721     .03317 |
 47. |  .001147   .0002702   .1189384   .1189163   .1290292   .0327287 |
 48. | .0044774   .0016964   .9734755   .9732951   .1287392   .0326553 |
 49. | .0044774   .0016964   .9734755   .9732951   .1272915   .0322888 |
 50. | .0008391   .0002564   .7014909   .7013609   .1270025   .0322157 |
     |-----------------------------------------------------------------|
 51. | .0053827   .0016714   .0233235   .0233191   .1272915   .0322888 |
 52. | .0022322   .0002611   .0803666   .0803517   .1278702   .0324353 |
 53. | .0156067   .0043404   .2773416   .2772903   .1287392   .0326553 |
 54. | .0003147   .0000482   .2430258   .2429808   .1310631   .0332437 |
 55. | .0100294   .0025733   .9708366   .9706568   .1325204   .0336127 |
     |-----------------------------------------------------------------|
 56. | .0007029    .000167   .3753979   .3753284   .1348599   .0342053 |
 57. | .0280535   .0061447    1.28525   1.285012   .1357396   .0344281 |
 58. | .0152896   .0033708   1.405572   1.405311   .1360332   .0345025 |
 59. | .0106821   .0016143   1.489532   1.489256   .1360332   .0345025 |
 60. | .0055086   .0011728   1.602565   1.602268   .1360332   .0345025 |
     |-----------------------------------------------------------------|
 61. | .0079304   .0020085   1.442738   1.442471   .1360332   .0345025 |
 62. | .0029361   .0009681   1.059012   1.058816   .1363268   .0345769 |
 63. | .0039236   .0013043   1.484611   1.484336   .1366207   .0346513 |
 64. | .0026209   .0006876   .7966263   .7964786   .1372088   .0348004 |
 65. | .0053613   .0014285   1.960274   1.959911   .1375031   .0348749 |
     |-----------------------------------------------------------------|
 66. | .0190736   .0065674   .8969148   .8967486   .1380921   .0350242 |
 67. | .0118866   .0027025   .8462504   .8460936   .1386818   .0351736 |
 68. | .0018835   .0003094   .5622563   .5621521   .1395673    .035398 |
 69. |        .          .          .          .   .1404542   .0356228 |
 70. |        .          .          .          .   .1419353   .0359982 |
     +-----------------------------------------------------------------+

. 
. desc

Contains data from tmp1.dta
  obs:           316                          
 vars:           198                          27 Jul 2020 11:28
---------------------------------------------------------------------------------------------------------------
              storage   display    value
variable name   type    format     label      variable label
---------------------------------------------------------------------------------------------------------------
iocode          str6    %9s                   
labforce_count  float   %9.0g                 
emp_count_tot   double  %12.0g                
pop             double  %9.0g                 
emprate         float   %9.0g                 
lfprate         float   %9.0g                 
ncode           float   %9.0g                 
iocode_name     str57   %57s                  
emp_count1_un~j float   %9.0g                 
emp_share1      float   %9.0g                 
emp_count2_un~j float   %9.0g                 
emp_share2      float   %9.0g                 
emp_count3_un~j float   %9.0g                 
emp_share3      float   %9.0g                 
emp_count4_un~j float   %9.0g                 
emp_share4      float   %9.0g                 
emp_count5_un~j float   %9.0g                 
emp_share5      float   %9.0g                 
wfh_share_dn1   float   %9.0g                 
wfh_share_mpw1  float   %9.0g                 
wfh_share_dn2   float   %9.0g                 
wfh_share_mpw2  float   %9.0g                 
wfh_share_dn3   float   %9.0g                 
wfh_share_mpw3  float   %9.0g                 
wfh_share_dn4   float   %9.0g                 
wfh_share_mpw4  float   %9.0g                 
wfh_share_dn5   float   %9.0g                 
wfh_share_mpw5  float   %9.0g                 
pp_share1       float   %9.0g                 
pp_share2       float   %9.0g                 
pp_share3       float   %9.0g                 
pp_share4       float   %9.0g                 
pp_share5       float   %9.0g                 
wfh_share_dn    float   %9.0g                 
wfh_share_mpw   float   %9.0g                 
wfh_dn          float   %9.0g                 
wfh_mpw         long    %12.0g                
pp_share        float   %9.0g                 Share of workers with high personal proximity at work
                                                (Mongey-Weinberg)
pp              long    %12.0g                
wfh_share       float   %9.0g                 Share of workers who can work at home (Dingel-Nieman)
june_hours      double  %10.0g                June_hours
febtomarch_ho~k double  %10.0g                FebtoMarch_hoursshock
marchtoapril_~k double  %10.0g                MarchtoApril_hoursshock
apriltomay_ho~k double  %10.0g                ApriltoMay_hoursshock
febtomay_hour~k double  %10.0g                FebtoMay_hoursshock
maytojune_hou~k double  %10.0g                MaytoJune_hoursshock
febtojune_hou~k double  %10.0g                FebtoJune_hoursshock
febtomarch_ad~t double  %10.0g                FebtoMarch_adjustment
marchtoapril_~t double  %10.0g                MarchtoApril_adjustment
apriltomay_ad~t double  %10.0g                ApriltoMay_adjustment
febtomay_adju~t double  %10.0g                FebtoMay_adjustment
maytojune_adj~t double  %10.0g                MaytoJune_adjustment
febtojune_adj~t double  %10.0g                FebtoJune_adjustment
febtomarch_up~d double  %10.0g                FebtoMarch_upperbound
marchtoapril_~d double  %10.0g                MarchtoApril_upperbound
apriltomay_up~d double  %10.0g                ApriltoMay_upperbound
febtomay_uppe~d double  %10.0g                FebtoMay_upperbound
maytojune_upp~d double  %10.0g                MaytoJune_upperbound
febtojune_upp~d double  %10.0g                FebtoJune_upperbound
labor_income_~e double  %10.0g                labor_income_share
date            float   %td                   
iso_3166_2_code str6    %9s                   
census_fips_c~e long    %12.0g                
retail_and_re~h int     %8.0g                 retail_and_recreation_percent_change_from_baseline
grocery_and_p~a int     %8.0g                 grocery_and_pharmacy_percent_change_from_baseline
parks_percent~i int     %8.0g                 parks_percent_change_from_baseline
transit_stati~_ int     %8.0g                 transit_stations_percent_change_from_baseline
workplaces_pe~b int     %8.0g                 workplaces_percent_change_from_baseline
residential_p~_ byte    %8.0g                 residential_percent_change_from_baseline
gmio            float   %9.0g                 
gmiw            float   %9.0g                 
gmio_sm         float   %9.0g                 ma: x(t)= gmio: window(3 1 3)
gmiw_sm         float   %9.0g                 ma: x(t)= gmiw: window(3 1 3)
school_frac     float   %9.0g                 
deaths          double  %8.0g                 (sum) deaths
confirmed       double  %12.0g                (sum) confirmed
deaths_thou     float   %9.0g                 Deaths (actual, thous)
confirmed_thou  float   %9.0g                 Confirmed cases (actual, thous)
deaths_weekly   float   %9.0g                 Weekly deaths, actual (thou)
deaths_daily    float   %9.0g                 Daily deaths, actual (thou)
ldeaths_weekly  float   %9.0g                 
day             float   %9.0g                 
month           float   %9.0g                 
quarter         float   %9.0g                 
year            float   %9.0g                 
yrmo            float   %9.0g                 
yrq             float   %9.0g                 
obsno           float   %9.0g                 
shock_Marchhrs  float   %9.0g                 
shock_Aprilhrs  float   %9.0g                 
shock_Mayhrs    float   %9.0g                 
shock_Junhrs    float   %9.0g                 
y99             float   %9.0g                 
labor_shock1    double  %10.0g                
labor_shock2    double  %10.0g                
labor_shock3    double  %10.0g                
labor_shock4    double  %10.0g                
labor_shock5    double  %10.0g                
labor_shock6    double  %10.0g                
labor_shock7    double  %10.0g                
labor_shock8    double  %10.0g                
labor_shock9    double  %10.0g                
labor_shock10   double  %10.0g                
labor_shock11   double  %10.0g                
labor_shock12   double  %10.0g                
labor_shock13   double  %10.0g                
labor_shock14   double  %10.0g                
labor_shock15   double  %10.0g                
labor_shock16   double  %10.0g                
labor_shock17   double  %10.0g                
labor_shock18   double  %10.0g                
labor_shock19   double  %10.0g                
labor_shock20   double  %10.0g                
labor_shock21   double  %10.0g                
labor_shock22   double  %10.0g                
labor_shock23   double  %10.0g                
labor_shock24   double  %10.0g                
labor_shock25   double  %10.0g                
labor_shock26   double  %10.0g                
labor_shock27   double  %10.0g                
labor_shock28   double  %10.0g                
labor_shock29   double  %10.0g                
labor_shock30   double  %10.0g                
labor_shock31   double  %10.0g                
labor_shock32   double  %10.0g                
labor_shock33   double  %10.0g                
labor_shock34   double  %10.0g                
labor_shock35   double  %10.0g                
labor_shock36   double  %10.0g                
labor_shock37   double  %10.0g                
labor_shock38   double  %10.0g                
labor_shock39   double  %10.0g                
labor_shock40   double  %10.0g                
labor_shock41   double  %10.0g                
labor_shock42   double  %10.0g                
labor_shock43   double  %10.0g                
labor_shock44   double  %10.0g                
labor_shock45   double  %10.0g                
labor_shock46   double  %10.0g                
labor_shock47   double  %10.0g                
labor_shock48   double  %10.0g                
labor_shock49   double  %10.0g                
labor_shock50   double  %10.0g                
labor_shock51   double  %10.0g                
labor_shock52   double  %10.0g                
labor_shock53   double  %10.0g                
labor_shock54   double  %10.0g                
labor_shock55   double  %10.0g                
labor_shock56   double  %10.0g                
labor_shock57   double  %10.0g                
labor_shock58   double  %10.0g                
labor_shock59   double  %10.0g                
labor_shock60   double  %10.0g                
labor_shock61   double  %10.0g                
labor_shock62   double  %10.0g                
labor_shock63   double  %10.0g                
labor_shock64   double  %10.0g                
labor_shock65   double  %10.0g                
labor_shock66   double  %10.0g                
labor_shock67   float   %9.0g                 
labor_shock68   float   %9.0g                 
epop            float   %9.0g                 
emp_count_tot~j float   %9.0g                 
emp_count1      float   %9.0g                 
epop1           float   %9.0g                 
emp_count2      float   %9.0g                 
epop2           float   %9.0g                 
emp_count3      float   %9.0g                 
epop3           float   %9.0g                 
emp_count4      float   %9.0g                 
epop4           float   %9.0g                 
emp_count5      float   %9.0g                 
epop5           float   %9.0g                 
pp_rel1         float   %9.0g                 
pp_rel2         float   %9.0g                 
pp_rel3         float   %9.0g                 
pp_rel4         float   %9.0g                 
x99             float   %9.0g                 
pp_rel5         float   %9.0g                 
w99             float   %9.0g                 
wfh_frac        double  %10.0g                
school_fac      float   %9.0g                 
gmio_sm_scaled  float   %9.0g                 
cmox1           float   %9.0g                 
cmhx1           float   %9.0g                 
cmwx1           float   %9.0g                 
cmox2           float   %9.0g                 
cmhx2           float   %9.0g                 
cmwx2           float   %9.0g                 
cmox3           float   %9.0g                 
cmhx3           float   %9.0g                 
cmwx3           float   %9.0g                 
cmox4           float   %9.0g                 
cmhx4           float   %9.0g                 
cmwx4           float   %9.0g                 
cmox5           float   %9.0g                 
cmhx5           float   %9.0g                 
cmwx5           float   %9.0g                 
---------------------------------------------------------------------------------------------------------------
Sorted by: date
     Note: Dataset has changed since last saved.

. cap drop _merge

. save "data\NPI_industry_data", replace
file data\NPI_industry_data.dta saved

. 
. * ------ Misc matrices, odss & ends --------
. mkmat deaths, mat(deaths)

. mkmat obsno, mat(obsno)

. mkmat emp_count1 emp_count2 emp_count3 emp_count4 emp_count5 in 1/68, mat(emp_count)

. mat emp_count_tot = emp_count*J(5,1,1)

. mat Lvec = emp_count'*J(68,1,1)

. mat Ltot = emp_count_tot'*J(rowsof(emp_count_tot),1,1)

. global Ltot = Ltot[1,1]

. gen psi = labor_income_share
(250 missing values generated)

. mkmat psi in 1/66, mat(psi)

. 
. * labor shocks by sector: historical and maximum until virus
. mkmat labor_shock1-labor_shock68, mat(lshock_npi)

. mkmat epop in 1/68, mat(epop)

. mkmat epop1 epop2 epop3 epop4 epop5 in 1/68, mat(epop_age)

. mat lshare_npi = hadamard(lshock_npi,J(rowsof(lshock_npi),1,1)*epop')

.  mat lshare_npi = lshare_npi[1...,1..66]

. mat lshockmax = J(68,1,0)

. 
. forvalues i = 1/68 {
  2.     mat lshockmax[`i',1] = 1 - 0.03*(lshock_npi[113,`i']<0.95) // Sectors for which employment was down by
>  more than 10% as of June empl report are capped at -3%
  3. }

. 
. * ---------- SEIQRD parameters (global) -------------------
. * IFR profile interpolated from Salje Science May 2020 https://science.sciencemag.org/content/early/2020/05/1
> 2/science.abc3517 interpolated 
. *  Interpolation from log-linear fit (Salje used log-linear) with US population weights, calculated in ifr_ag
> e_population_adj.xlsx
. if $nage==5 {
.  mat IFR00 =  (0.001    \ 0.020    \ 0.280      \ 1.349   \ 7.177)/100 // Salje Science May 2020 (adjusted fo
> r our age groups)
.  mat a98 = IFR00'*Nvec/N
.  mat IFR00 = (1.2/a98[1,1])*IFR00 // factor of 1.41 to adjust for typical simulated infection rate age distn
.  
.  * fractional distribution of initially infected
.  mat I00 = (1.75 \ 10.15 \ 12.25 \ 4.55 \ 6.30)
.  mat a99 = I00'*J(5,1,1)
.  mat I00 = I00/a99[1,1]
. }

. if $nage==1 {
.  mat IFR00 = 1
.  mat I00 = 1
.  forvalues i = 1/$numnpis {
  2.   mat cnormalized = hadamard(c_`i',Nvec*Nvecinv')
  3.   mat eigenvalues r c = cnormalized
  4.   mat c_`i' = r[1,1]
  5.  }
.  mat Nvec = N
.  mat Nvecinv = 1/N
. }

. 
. * ----------------------------------------------------------------------------- 
. *  Read in POLYMOD contact matrices
. *    compute conditional contact matrices
. *    reweight for US 
. * ----------------------------------------------------------------------------- 
. preserve 

.  foreach cc in "home_mean" "other_mean" "work_mean" {
  2.   import delimited using "$dpath/contact_`cc'.csv", rowrange(2) colrange(2) clear
  3.   destring v*, replace
  4.   mkmat v*, mat(c)
  5.   mat c`cc' = c
  6.   mat list c`cc'
  7.  }
(5 vars, 5 obs)
v1 already numeric; no replace
v2 already numeric; no replace
v3 already numeric; no replace
v4 already numeric; no replace
v5 already numeric; no replace

chome_mean[5,5]
           v1         v2         v3         v4         v5
r1  1.4490775   1.798893  .76863468  .14907749  .07269373
r2  1.1207547  1.3264151  .70518869  .13349056  .07311321
r3  .71412683  1.0489433  1.0389322  .17130144  .14627364
r4  .49530515  .88497651  .64319247  .62676054  .17136151
r5   .4649123  .71052629   .7719298  .31578946  .42982456
(5 vars, 5 obs)
v1 already numeric; no replace
v2 already numeric; no replace
v3 already numeric; no replace
v4 already numeric; no replace
v5 already numeric; no replace

cother_mean[5,5]
           v1         v2         v3         v4         v5
r1  7.3420663  2.1723247  .94169742  .16014761  .07749078
r2  .90377361  3.4990566  1.0891509  .19245283  .08584905
r3  .74416018  2.0456061  1.7130145  .38431591  .20634037
r4  .29812208  1.5211267  1.5962441  .90845072  .33802816
r5  .21929824  .69298244  .92105263  .65789473  .28947368
(5 vars, 5 obs)
v1 already numeric; no replace
v2 already numeric; no replace
v3 already numeric; no replace
v4 already numeric; no replace
v5 already numeric; no replace

cwork_mean[5,5]
           v1         v2         v3         v4         v5
r1  .06937269  .11365314  .04612546   .0099631  .00073801
r2  .47311321  2.8627357      1.275  .10613208  .06886792
r3  .33704117  1.8075639  1.3370411  .09010011   .0945495
r4  .03755869  .26760563  .22065727  .02347418  .03521127
r5  .01754386  .14035088  .01754386  .00877193          0

.  * sampling fractions by age in polymod
.  import delimited using "$dpath/fractions_by_category.csv", rowrange(2) colrange(2) clear
(3 vars, 5 obs)

.  mkmat fraction_work fraction_home fraction_other, mat(fpolymod)

.  mat list fpolymod

fpolymod[5,3]
    fraction_w~k  fraction_h~e  fraction_o~r
r1     .04575646     .96383762      .8785978
r2     .49245283     .91367924     .81886792
r3     .39377084     .89822024     .78698552
r4     .11267605     .87323946     .77464789
r5     .06140351     .89473683     .65789473

. restore

. 
. mat list chome_mean

chome_mean[5,5]
           v1         v2         v3         v4         v5
r1  1.4490775   1.798893  .76863468  .14907749  .07269373
r2  1.1207547  1.3264151  .70518869  .13349056  .07311321
r3  .71412683  1.0489433  1.0389322  .17130144  .14627364
r4  .49530515  .88497651  .64319247  .62676054  .17136151
r5   .4649123  .71052629   .7719298  .31578946  .42982456

. mat list cother_mean

cother_mean[5,5]
           v1         v2         v3         v4         v5
r1  7.3420663  2.1723247  .94169742  .16014761  .07749078
r2  .90377361  3.4990566  1.0891509  .19245283  .08584905
r3  .74416018  2.0456061  1.7130145  .38431591  .20634037
r4  .29812208  1.5211267  1.5962441  .90845072  .33802816
r5  .21929824  .69298244  .92105263  .65789473  .28947368

. mat list fpolymod

fpolymod[5,3]
    fraction_w~k  fraction_h~e  fraction_o~r
r1     .04575646     .96383762      .8785978
r2     .49245283     .91367924     .81886792
r3     .39377084     .89822024     .78698552
r4     .11267605     .87323946     .77464789
r5     .06140351     .89473683     .65789473

. 
. * Create normalize mean polymod contact matrices so they are conditional on being in that state
. local j = 0

. foreach cc in "work" "home" "other" {
  2.  local j = `j'+1
  3.  mat cn`cc'_mean = J(5,5,0)
  4.  forvalue i = 1/5 {
  5.    mat cn`cc'_mean[`i',1] = c`cc'_mean[`i',1...]/fpolymod[`i',`j']
  6.  }
  7.  mat cn`cc'_tot = cn`cc'_mean*J(5,1,1) // Mean contacts by age by activity
  8.  mat list cn`cc'_tot 
  9. }

cnwork_tot[5,1]
           c1
r1  5.2419353
r2  9.7183906
r3  9.3107346
r4  5.1875001
r5          3

cnhome_tot[5,1]
           c1
r1  4.3973967
r2  3.6763036
r3  3.4730651
r4  3.2311826
r5  3.0098039

cnother_tot[5,1]
           c1
r1  12.171356
r2   7.046659
r3  6.4720849
r4  6.0181818
r5  4.2266667

. 
. * Reweighted mean work polymod matrix, reweighted for baseline US population shares by age
. mat lf99 = J(5,1,0)

. forvalues i = 1/5 {
  2.  qui su epop`i'
  3.  mat lf99[`i',1] = r(N)*r(mean)
  4. }

. mat cwork_USwt = hadamard(lf99*J(1,5,1),cnwork_mean)

. mat list cwork_USwt

cwork_USwt[5,5]
           c1         c2         c3         c4         c5
r1  .09829618  .16103843  .06535651  .01411701   .0010457
r2  .72277838  4.3734216  1.9478264  .16213872  .10521001
r3  .59328898  3.1818301  2.3535753    .158602   .1664342
r4  .08763579  .62440501  .51486027  .05477237  .08215856
r5  .01900464  .15203712  .01900464  .00950232          0

. * Pull out rows of other contact matrix for subsequent individual manipulation 
. local m "cother_mean"

. forvalues i = 1/5 {
  2.  mat `m'`i' = J(5,5,0)
  3.  mat `m'`i'[`i',1] = `m'[`i',1...]
  4. }

. mat `m'23 = `m'2 + `m'3

. mat `m'24 = `m'2 + `m'3 + `m'4

. mat `m'25 = `m'2 + `m'3 + `m'4 + `m'5

. *
. 
. * Adjustment matrix for reduced infectiousness of children
. *   Note will want to vary this for sensitivity analysis. See Kong-Li memo 060620
. mat cmat_adjust_kids = J(5,5,1)

. mat cmat_adjust_kids[1,2] = J(1,4,$inf_adults2kids)

. mat cmat_adjust_kids[2,1] = J(4,1,$inf_kids2adults)

. mat cmat_adjust_kids[1,1] = ($inf_kids2adults+$inf_adults2kids)/2

. 
. * Create contact summary measure (maxReval) for use in nage=1 model, no SD measures (phifac=1)
. local T = _N

. qui gen maxReval_un = .

. qui gen maxReval = .

. forvalues t = 1/`T' {
  2.  if (cmhx1[`t']~=.)*(cmox1[`t']~=.)*(cmwx1[`t']~=.) {
  3.   mat cwork = J(5,5,0)
  4.   mat cother = J(5,5,0)
  5.   mat chome = J(5,5,0)
  6.   forvalues a = 1/5 {
  7.    mat cwork[`a',1]  = cmwx`a'[`t']*cnwork_mean[`a',1...] 
  8.    mat cother[`a',1] = cmox`a'[`t']*cother_mean[`a',1...]
  9.    mat chome[`a',1]  = cmhx`a'[`t']*chome_mean[`a',1...]
 10.   }
 11.   mat ctot = chome + cother + cwork
 12.   if `t'==11 {
 13.       mat ctot0 = ctot // basline contact matrix is Monday March 2
 14.   }
 15.   if `t'==55 {
 16.       mat ctot_April15 = ctot // contact matrix on April 15
 17.   }
 18.   mat cmat = hadamard(cmat_adjust_kids,ctot)
 19.   mat cnormalized = hadamard(cmat,Nvec*Nvecinv')
 20.   mat eigenvalues r c = cnormalized
 21.   qui replace maxReval = r[1,1] in `t'/`T'
 22.   mat cnormalized = hadamard(ctot,Nvec*Nvecinv')
 23.   mat eigenvalues r c = cnormalized
 24.   qui replace maxReval_un = r[1,1] in `t'/`T'
 25.  }
 26. }

. *tsline maxReval maxReval_un in 1/100
. su maxReval if tin(22Feb2020,03Mar2020)

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    maxReval |         11    12.68447    .0898135   12.53605   12.78508

. global maxReval0 = r(mean)

. mkmat maxReval, mat(maxReval)

. mat maxReval_input =  J(`T',1,$maxReval0) // required initialization

. dis "Baseline maxReval = " $maxReval0
Baseline maxReval = 12.684465

. 
. * ----------------------------------------------------------------------------- 
. *       Derivatives of maximum eigenvalue for adding workers to sector i
. *         Evaluate derivatives for baseline contact matrix
. * ----------------------------------------------------------------------------- 
. sca numericalderivfac = 1000

. gen mderiv = .
(316 missing values generated)

. mat cmat = hadamard(cmat_adjust_kids,ctot0)

. mat cnormalized = hadamard(cmat,Nvec*Nvecinv')

. mat eigenvalues r c = cnormalized

. local maxrevalmc_0 = r[1,1]

. forvalues a = 1/5 {
  2.   gen depop`a' = (numericalderivfac/Nvec[`a',1])*(emp_count`a'/emp_count_tot)  // increment in epop by age
>  for numerical derivative 
  3. }
(248 missing values generated)
(248 missing values generated)
(248 missing values generated)
(248 missing values generated)
(248 missing values generated)

. forvalues i = 1/66 {
  2.  mat dcwork = J(5,5,0)
  3.  forvalues a = 1/5 {
  4.    mat dcwork[`a',1]  = depop`a'[`i']*pp_rel`a'[`i']*cnwork_mean[`a',1...]
  5.  }
  6.  mat ctot1 = ctot0 + dcwork
  7.  mat cmat = hadamard(cmat_adjust_kids,ctot1)
  8.  mat cnormalized = hadamard(cmat,Nvec*Nvecinv')
  9.  mat eigenvalues r c = cnormalized
 10.  local maxrevalmc_1 = r[1,1]
 11.  qui replace mderiv = (`maxrevalmc_1' - `maxrevalmc_0')/numericalderivfac in `i'/`i'
 12. }

. 
. * ----------------------------------------------------------------------------- 
. *          Create industry contribution index (theta) 
. * ----------------------------------------------------------------------------- 
. gen theta_gdp_raw = (psi/emp_count_tot)/((0.05539/0.214)*mderiv)
(250 missing values generated)

. gen psi_per_worker = psi/emp_count_tot
(250 missing values generated)

. winsor theta_gdp_raw, gen(theta_gdp) h(3)

.  su theta_gdp in 1/66, d

             theta_gdp_raw, Winsorized extreme 3
-------------------------------------------------------------
      Percentiles      Smallest
 1%      .109523        .109523
 5%      .109523        .109523
10%     .1333413        .109523       Obs                  66
25%     .3336748        .109523       Sum of Wgt.          66

50%     .8549862                      Mean           1.600582
                        Largest       Std. Dev.      2.591808
75%     1.387634       10.54043
90%     3.209994       10.54043       Variance        6.71747
95%     10.54043       10.54043       Skewness       2.760262
99%     10.54043       10.54043       Kurtosis       9.497972

.  replace theta_gdp = (theta_gdp - r(mean))/r(sd)
(66 real changes made)

.  qui replace theta_gdp = 0 in 67/68

.  mkmat theta_gdp in 1/68, mat(theta_gdp)

.  *
. preserve

.  keep in 1/68
(248 observations deleted)

.  keep ncode iocode iocode_name psi mderiv emp_count_tot psi_per_worker theta_gdp_raw theta_gdp

.  save "data\theta_gdp", replace
file data\theta_gdp.dta saved

.  sort theta_gdp

.  export excel iocode ncode iocode_name psi emp_count_tot psi_per_worker mderiv theta_gdp_raw theta_gdp using 
> "data\theta_gdp.xlsx", replace
file data\theta_gdp.xlsx saved

. restore

. list theta_gdp in 1/70

     +-----------+
     | theta_gdp |
     |-----------|
  1. | -.2421288 |
  2. | -.1119411 |
  3. |   3.44927 |
  4. | -.1378311 |
  5. | -.0592485 |
     |-----------|
  6. | -.2630649 |
  7. | -.5255524 |
  8. | -.4075754 |
  9. | -.2861017 |
 10. | -.0708723 |
     |-----------|
 11. | -.1814296 |
 12. | -.2296646 |
 13. |  .3314509 |
 14. | -.1430639 |
 15. | -.4481522 |
     |-----------|
 16. | -.2892466 |
 17. |  -.431935 |
 18. | -.4695451 |
 19. | -.4201268 |
 20. | -.3159987 |
     |-----------|
 21. | -.1609744 |
 22. | -.2492329 |
 23. | -.3123973 |
 24. |  .0254374 |
 25. | -.0759637 |
     |-----------|
 26. | -.2954118 |
 27. |  .2423154 |
 28. | -.5080966 |
 29. | -.5752969 |
 30. | -.5656387 |
     |-----------|
 31. | -.5631488 |
 32. | -.4487244 |
 33. | -.1744772 |
 34. | -.4223417 |
 35. |  .0603535 |
     |-----------|
 36. | -.5752969 |
 37. | -.0349365 |
 38. | -.2290017 |
 39. | -.4620456 |
 40. |  .6209609 |
     |-----------|
 41. | -.3834832 |
 42. |  -.082162 |
 43. | -.2242783 |
 44. | -.2464106 |
 45. |   3.44927 |
     |-----------|
 46. |  1.515287 |
 47. | -.5675076 |
 48. | -.5752969 |
 49. | -.4189315 |
 50. | -.2189579 |
     |-----------|
 51. |   3.44927 |
 52. |  2.419688 |
 53. |  .4113526 |
 54. |   3.44927 |
 55. | -.4570401 |
     |-----------|
 56. | -.2433542 |
 57. | -.5752969 |
 58. | -.5011098 |
 59. | -.5188103 |
 60. |  -.547192 |
     |-----------|
 61. | -.5661071 |
 62. | -.5159118 |
 63. | -.5617458 |
 64. | -.4888122 |
 65. |  -.572306 |
     |-----------|
 66. | -.4727471 |
 67. |         0 |
 68. |         0 |
 69. |         . |
 70. |         . |
     +-----------+

. 
. * ----------------------------------------------------------------------------- 
. *         Initialization odds and ends 
. * ----------------------------------------------------------------------------- 
. * Initialize removal to quarantine spike to off, overwite for removal experiment
. global tremove = "20May2020"

.  cap drop e98

.  gen e98 = tin(,$tremove)

.  qui su e98

.   global ndate_remove = r(sum)

. global nremove = 0

. gen Q2avg = tin(01Apr2020,30Jun2020)

. gen Q3avg = tin(01Jul2020,30Sep2020)

. gen Q4avg = tin(01Oct2020,31Dec2020)

. forvalues q = 2/4 {
  2.         mkmat Q`q'avg, mat(Q`q'avg)
  3.         qui su Q`q'avg, d
  4.         mat Q`q'avg = Q`q'avg/r(sum)
  5. }

. format date %td

. sort date

. 
. /* Figure: Contact matrix heat maps 
> * example contact matrix with 7% unemployment rate (non-nuanced reopening), partial sequestering 75+, ages 64
> + don't go to work
> mat coth_fac_ex = J(5,5,1)
> mat coth_fac_ex[1,1] = 0.3*J(1,4,1)
> mat coth_fac_ex[1,5] = 0.25*J(5,1,1)
> mat coth_fac_ex[5,1] = 0.25*J(1,5,1)
> mat ctot_ex = hadamard((J(4,1,1)\0.25)*J(1,5,1),chome_mean) + hadamard(coth_fac_ex,cother_mean) + hadamard((1
> \1\1\0\0)*J(1,5,1),cwork_USwt)
> foreach cmat in "ctot0" "ctot_April15" "ctot_ex" { 
>  cap drop contacta contactb cc1 cc2 cc3 cc4 cc5 ctotplot
>  svmat `cmat', names(cc)
>  gen contacta = .
>  gen contactb = .
>  gen ctotplot = .
>  local j = 0
>  forvalues a = 1/5 { 
>         forvalues b = 1/5 {
>                 local j = `j'+1
>                 qui replace contacta = `a' in `j'/`j'
>                 qui replace contactb = `b' in `j'/`j'
>                 qui replace ctotplot = cc`a'[`b'] in `j'/`j'
>         }
>  }
>  twoway contour ctotplot contacta contactb in 1/25, heatmap ecolor(cranberry) crule(int) ccuts(0(0.2)9) xtitl
> e("") ytitle("")
>  save "figs/cmat_heatmap_`cmat'.png", replace
>  preserve
>   keep ctotplot contacta contactb 
>   keep in 1/25
>   save "figs/cmat_heatmap_`cmat'.dta", replace
>  restore
> }
> */
. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
. 
end of do-file

. 
. * disable PID controller for estimation
. global PIDdate "18May2021"

. gen PID = 0

. global ndate_PID = _N+1

. local csfx ""

. mkmat PID, mat(PID)

. 
. * disable derivatives
. *mat delta_lshare = J(1,68,0)
. 
. * disable quarantine options
. *global nremove = 0
. * global tremove = "15Jul2021"
. * cap drop e98
. * gen e98 = tin(,$tremove)
. * qui su e98
. *  global ndate_remove = r(sum)
. *gen qrate = 0 // quarantine rate
. 
. * Read in estimated parms from file
. local parmfile "estn\Estd_parms_5_070620_BPEA_final_base.xlsx"

. preserve

.  qui import excel using `parmfile', sheet(parms) case(lower) clear

.  mkmat *, mat(parms_all)

.  mat parms = parms_all

.  qui import excel using `parmfile', sheet(vcv) case(lower) clear

.  mkmat *, mat(vecvcv_all)

.  mat vecvcv = vecvcv_all

. restore

. *
. * Evaluate derivatives over estimation period
. 
. global varout = 1

. local np = rowsof(parms)

. gen edates = 0

. forvalues p = 1/`np' {
  2.    cap drop dtot_p* wtot_p* 
  3.         local nparms = parms[1,1]
  4.     mat bhat = parms[`p',2..`nparms'+1]
  5.         mat vtemp = vecvcv[`p',1...]'
  6.     mata: st_matrix("vcv", colshape( st_matrix("vtemp")', 5) )
  7.     mat list vcv
  8.         *mat vcv = 9*vcv // test code
.                 
.         global nedate1 = round(parms[`p',1+2*`nparms'+1],.01)
  9.         global nedate2 = round(parms[`p',1+2*`nparms'+2],.01)
 10.         global edate2 = date[$nedate2]
 11.         global nedate3 = $nedate2
 12.         global ndate_END = $nedate2
 13.         
.          qui replace edates = (_n>=$nedate1)*(_n<=$nedate2)
 14.     local R0 = round(parms[`p',1+2*`nparms'+3],.01)
 15.     global deltabar = round(parms[`p',1+2*`nparms'+4],.001)
 16.     global gamma = parms[`p',1+2*`nparms'+5]
 17.     global sigma = parms[`p',1+2*`nparms'+6]
 18.         local deltabar = $deltabar
 19.     cap drop qrate
 20.     gen qrate = 0 // quarantine rate - not used in estimation but needs to be defined
 21.     * qui replace qrate = $gamma*`fquar'/100 if tin(01Jul2020,)
.         
.     *local beta = $gamma*`R0'/$maxReval0
.     mat IFR = `deltabar'*IFR00 
 22.     cap drop x99
 23.     gen x99 = 0
 24.         dis "here1"
 25.     *============================================*
.     nlseird_pid x99 if edates, at(bhat)
 26.     *============================================*
.         keep if tin(,$ENDdate)
 27. 
.     cap drop r0_p`p' 
 28.     gen dtot_p`p' = Dtot
 29.     gen wtot_p`p' = Wtot
 30.     gen r0_p`p' = r0
 31.     gen reff_p`p' = reff
 32.         gen phifac_p`p' = phifac
 33.         
.     * compute derivatives and SEs wrt I0 and beta (not phi)
.         global eps = 1e-2
 34.         forvalues j = 1/`nparms' {
 35.          mat delbhat = J(1,colsof(bhat),0)
 36.          mat delbhat[1,`j'] = $eps
 37.          mat bhat_eps = bhat + delbhat
 38.      nlseird_pid x99 if edates, at(bhat_eps)
 39.          
.           cap drop wtot_eps`j' r0_eps`j' reff_eps`j' 
 40.           qui gen wtot_eps`j' = (Wtot-wtot_p`p')/$eps
 41.           qui gen r0_eps`j' = (r0-r0_p`p')/$eps
 42.           qui gen reff_eps`j' = (reff-reff_p`p')/$eps
 43.         }
 44.     foreach vv in "wtot" "r0" "reff" {
 45.      cap drop d`vv'_p`p'_*
 46.          qui gen d`vv'_p`p'_se = 0
 47.          forvalues j = 1/`nparms' {
 48.                 forvalues k = 1/`nparms' {
 49.                         qui replace d`vv'_p`p'_se = d`vv'_p`p'_se  + `vv'_eps`j'*`vv'_eps`k'*vcv[`j',`k']
 50.                 }
 51.          }
 52.          qui replace d`vv'_p`p'_se = sqrt(d`vv'_p`p'_se)
 53.          qui gen d`vv'_p`p'_q05 = `vv'_p`p' - 1.96*d`vv'_p`p'_se
 54.          qui gen d`vv'_p`p'_q10 = `vv'_p`p' - 1.28*d`vv'_p`p'_se
 55.          qui gen d`vv'_p`p'_q33 = `vv'_p`p' - d`vv'_p`p'_se
 56.          qui gen d`vv'_p`p'_q67 = `vv'_p`p' + d`vv'_p`p'_se
 57.          qui gen d`vv'_p`p'_q90 = `vv'_p`p' + 1.28*d`vv'_p`p'_se
 58.          qui gen d`vv'_p`p'_q95 = `vv'_p`p' + 1.96*d`vv'_p`p'_se
 59.         }
 60. }       

symmetric vcv[5,5]
            c1          c2          c3          c4          c5
r1   .29575479
r2   .00005686   8.952e-07
r3  -.00898702  -4.192e-06   .00140138
r4  -.01655485  -5.034e-06   .00023474   .00153907
r5  -.00026577  -6.074e-08   2.687e-06   .00001711   2.721e-07
here1

bhat[1,5]
            B          C          D          E          F
r1   5.209986  .00330983  .79641238  .82336053  .05195851
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  7.405e-06
r2  .00014811
r3  .00207349
r4   .0099898
r5  .05314812
gamma .22140276
beta .05195851
sigma .22794103
IFR_sim .00375515
(0 observations deleted)
(191 missing values generated)
(191 missing values generated)
(191 missing values generated)
(191 missing values generated)

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1   5.219986  .00330983  .79641238  .82336053  .05195851
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  7.405e-06
r2  .00014811
r3  .00207349
r4   .0099898
r5  .05314812
gamma .22140276
beta .05195851
sigma .22794103
IFR_sim .00375522

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1   5.209986  .01330983  .79641238  .82336053  .05195851
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  7.405e-06
r2  .00014811
r3  .00207349
r4   .0099898
r5  .05314812
gamma .22140276
beta .05195851
sigma .22794103
IFR_sim .0037547

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1   5.209986  .00330983  .80641238  .82336053  .05195851
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  7.405e-06
r2  .00014811
r3  .00207349
r4   .0099898
r5  .05314812
gamma .22140276
beta .05195851
sigma .22794103
IFR_sim .00375599

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1   5.209986  .00330983  .79641238  .83336053  .05195851
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  7.405e-06
r2  .00014811
r3  .00207349
r4   .0099898
r5  .05314812
gamma .22140276
beta .05195851
sigma .22794103
IFR_sim .0037551

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1   5.209986  .00330983  .79641238  .82336053  .06195851
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  7.405e-06
r2  .00014811
r3  .00207349
r4   .0099898
r5  .05314812
gamma .22140276
beta .06195851
sigma .22794103
IFR_sim .00398045

symmetric vcv[5,5]
            c1          c2          c3          c4          c5
r1   .23569057
r2   -.0001998   7.034e-06
r3  -.00620247   4.867e-06   .00159522
r4  -.01473623   .00001282   .00008742   .00152506
r5  -.00024905   1.513e-07   9.771e-07   .00001818   2.945e-07
here1

bhat[1,5]
            B          C          D          E          F
r2   4.932267  .01224093  .83201353   .8043494  .05063542
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  9.257e-06
r2  .00018513
r3  .00259187
r4  .01248725
r5  .06643515
gamma .22140276
beta .05063542
sigma .22794103
IFR_sim .00466313
(0 observations deleted)
(191 missing values generated)
(191 missing values generated)
(191 missing values generated)
(191 missing values generated)

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1   4.942267  .01224093  .83201353   .8043494  .05063542
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  9.257e-06
r2  .00018513
r3  .00259187
r4  .01248725
r5  .06643515
gamma .22140276
beta .05063542
sigma .22794103
IFR_sim .00466321

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1   4.932267  .02224093  .83201353   .8043494  .05063542
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  9.257e-06
r2  .00018513
r3  .00259187
r4  .01248725
r5  .06643515
gamma .22140276
beta .05063542
sigma .22794103
IFR_sim .00466244

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1   4.932267  .01224093  .84201353   .8043494  .05063542
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  9.257e-06
r2  .00018513
r3  .00259187
r4  .01248725
r5  .06643515
gamma .22140276
beta .05063542
sigma .22794103
IFR_sim .00466407

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1   4.932267  .01224093  .83201353   .8143494  .05063542
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  9.257e-06
r2  .00018513
r3  .00259187
r4  .01248725
r5  .06643515
gamma .22140276
beta .05063542
sigma .22794103
IFR_sim .0046631

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1   4.932267  .01224093  .83201353   .8043494  .06063542
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  9.257e-06
r2  .00018513
r3  .00259187
r4  .01248725
r5  .06643515
gamma .22140276
beta .06063542
sigma .22794103
IFR_sim .00493922

symmetric vcv[5,5]
            c1          c2          c3          c4          c5
r1   .18449221
r2  -.00003915   6.458e-07
r3  -.00669251   1.035e-06   .00157026
r4  -.01315989   6.323e-06   .00015255    .0016103
r5  -.00020828   3.391e-08   1.234e-06    .0000173   2.720e-07
here1

bhat[1,5]
            B          C          D          E          F
r3  4.1497144  .00299252  .84388831   .8086978  .05049684
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00001111
r2  .00022216
r3  .00311024
r4   .0149847
r5  .07972218
gamma .22140276
beta .05049684
sigma .22794103
IFR_sim .0055874
(0 observations deleted)
(191 missing values generated)
(191 missing values generated)
(191 missing values generated)
(191 missing values generated)

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1  4.1597144  .00299252  .84388831   .8086978  .05049684
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00001111
r2  .00022216
r3  .00311024
r4   .0149847
r5  .07972218
gamma .22140276
beta .05049684
sigma .22794103
IFR_sim .0055875

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1  4.1497144  .01299252  .84388831   .8086978  .05049684
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00001111
r2  .00022216
r3  .00311024
r4   .0149847
r5  .07972218
gamma .22140276
beta .05049684
sigma .22794103
IFR_sim .0055864

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1  4.1497144  .00299252  .85388831   .8086978  .05049684
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00001111
r2  .00022216
r3  .00311024
r4   .0149847
r5  .07972218
gamma .22140276
beta .05049684
sigma .22794103
IFR_sim .00558848

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1  4.1497144  .00299252  .84388831   .8186978  .05049684
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00001111
r2  .00022216
r3  .00311024
r4   .0149847
r5  .07972218
gamma .22140276
beta .05049684
sigma .22794103
IFR_sim .00558739

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1  4.1497144  .00299252  .84388831   .8086978  .06049684
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00001111
r2  .00022216
r3  .00311024
r4   .0149847
r5  .07972218
gamma .22140276
beta .06049684
sigma .22794103
IFR_sim .00590812

symmetric vcv[5,5]
            c1          c2          c3          c4          c5
r1   .13747299
r2           0           0
r3  -.00330472           0   .00124965
r4  -.01197636           0  -.00005999   .00172119
r5  -.00018912           0  -8.366e-07     .000019   2.912e-07
here1

bhat[1,5]
            B          C          D          E          F
r4  3.6350783  .00457452  .85385314  .82077513  .05027424
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00001296
r2  .00025919
r3  .00362862
r4  .01748215
r5  .09300921
gamma .22140276
beta .05027424
sigma .22794103
IFR_sim .00650783
(0 observations deleted)
(191 missing values generated)
(191 missing values generated)
(191 missing values generated)
(191 missing values generated)

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1  3.6450783  .00457452  .85385314  .82077513  .05027424
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00001296
r2  .00025919
r3  .00362862
r4  .01748215
r5  .09300921
gamma .22140276
beta .05027424
sigma .22794103
IFR_sim .00650793

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1  3.6350783  .01457452  .85385314  .82077513  .05027424
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00001296
r2  .00025919
r3  .00362862
r4  .01748215
r5  .09300921
gamma .22140276
beta .05027424
sigma .22794103
IFR_sim .00650652

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1  3.6350783  .00457452  .86385314  .82077513  .05027424
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00001296
r2  .00025919
r3  .00362862
r4  .01748215
r5  .09300921
gamma .22140276
beta .05027424
sigma .22794103
IFR_sim .00650904

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1  3.6350783  .00457452  .85385314  .83077513  .05027424
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00001296
r2  .00025919
r3  .00362862
r4  .01748215
r5  .09300921
gamma .22140276
beta .05027424
sigma .22794103
IFR_sim .00650783

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1  3.6350783  .00457452  .85385314  .82077513  .06027424
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00001296
r2  .00025919
r3  .00362862
r4  .01748215
r5  .09300921
gamma .22140276
beta .06027424
sigma .22794103
IFR_sim .00687233

symmetric vcv[5,5]
            c1          c2          c3          c4          c5
r1   .12399101
r2  -4.585e-06   .00001766
r3  -.00401823   -.0000118    .0015562
r4  -.01256502   .00001775   .00005333   .00196354
r5  -.00018893   4.878e-08   5.525e-07   .00002176   3.169e-07
here1

bhat[1,5]
            B          C          D          E          F
r5  3.4105265  .00910787  .87629562  .80424388  .04970444
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00001481
r2  .00029621
r3  .00414699
r4   .0199796
r5  .10629624
gamma .22140276
beta .04970444
sigma .22794103
IFR_sim .00741803
(0 observations deleted)
(191 missing values generated)
(191 missing values generated)
(191 missing values generated)
(191 missing values generated)

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1  3.4205265  .00910787  .87629562  .80424388  .04970444
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00001481
r2  .00029621
r3  .00414699
r4   .0199796
r5  .10629624
gamma .22140276
beta .04970444
sigma .22794103
IFR_sim .00741814

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1  3.4105265  .01910787  .87629562  .80424388  .04970444
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00001481
r2  .00029621
r3  .00414699
r4   .0199796
r5  .10629624
gamma .22140276
beta .04970444
sigma .22794103
IFR_sim .00741653

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1  3.4105265  .00910787  .88629562  .80424388  .04970444
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00001481
r2  .00029621
r3  .00414699
r4   .0199796
r5  .10629624
gamma .22140276
beta .04970444
sigma .22794103
IFR_sim .00741931

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1  3.4105265  .00910787  .87629562  .81424388  .04970444
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00001481
r2  .00029621
r3  .00414699
r4   .0199796
r5  .10629624
gamma .22140276
beta .04970444
sigma .22794103
IFR_sim .00741804

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1  3.4105265  .00910787  .87629562  .80424388  .05970444
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00001481
r2  .00029621
r3  .00414699
r4   .0199796
r5  .10629624
gamma .22140276
beta .05970444
sigma .22794103
IFR_sim .00782683

symmetric vcv[5,5]
            c1          c2          c3          c4          c5
r1   .10075571
r2  -.00012287   .00002244
r3  -.00389904   .00001856   .00149654
r4  -.01185784   .00002562   .00008091   .00218153
r5  -.00017237   1.440e-07   8.900e-07   .00002314   3.266e-07
here1

bhat[1,5]
            B          C          D          E          F
r6  2.9323807  .00646067  .87930087  .82574673  .04986565
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00001666
r2  .00033324
r3  .00466536
r4  .02247706
r5  .11958326
gamma .22140276
beta .04986565
sigma .22794103
IFR_sim .00834697
(0 observations deleted)
(191 missing values generated)
(191 missing values generated)
(191 missing values generated)
(191 missing values generated)

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1  2.9423807  .00646067  .87930087  .82574673  .04986565
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00001666
r2  .00033324
r3  .00466536
r4  .02247706
r5  .11958326
gamma .22140276
beta .04986565
sigma .22794103
IFR_sim .0083471

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1  2.9323807  .01646067  .87930087  .82574673  .04986565
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00001666
r2  .00033324
r3  .00466536
r4  .02247706
r5  .11958326
gamma .22140276
beta .04986565
sigma .22794103
IFR_sim .00834515

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1  2.9323807  .00646067  .88930087  .82574673  .04986565
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00001666
r2  .00033324
r3  .00466536
r4  .02247706
r5  .11958326
gamma .22140276
beta .04986565
sigma .22794103
IFR_sim .0083484

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1  2.9323807  .00646067  .87930087  .83574673  .04986565
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00001666
r2  .00033324
r3  .00466536
r4  .02247706
r5  .11958326
gamma .22140276
beta .04986565
sigma .22794103
IFR_sim .00834699

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1  2.9323807  .00646067  .87930087  .82574673  .05986565
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00001666
r2  .00033324
r3  .00466536
r4  .02247706
r5  .11958326
gamma .22140276
beta .05986565
sigma .22794103
IFR_sim .00879468

symmetric vcv[5,5]
            c1          c2          c3          c4          c5
r1   .07741251
r2   .00013514   .00003601
r3   -.0018859   .00004282   .00149528
r4  -.00920219  -9.882e-06  -.00010831   .00178852
r5  -.00013858  -4.658e-07  -2.798e-06   .00001884   2.804e-07
here1

bhat[1,5]
            B          C          D          E          F
r7  2.8321382  .00984149   .8880916  .80417644  .04941036
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00001851
r2  .00037027
r3  .00518374
r4  .02497451
r5  .13287029
gamma .22140276
beta .04941036
sigma .22794103
IFR_sim .00925529
(0 observations deleted)
(191 missing values generated)
(191 missing values generated)
(191 missing values generated)
(191 missing values generated)

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1  2.8421382  .00984149   .8880916  .80417644  .04941036
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00001851
r2  .00037027
r3  .00518374
r4  .02497451
r5  .13287029
gamma .22140276
beta .04941036
sigma .22794103
IFR_sim .00925542

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1  2.8321382  .01984149   .8880916  .80417644  .04941036
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00001851
r2  .00037027
r3  .00518374
r4  .02497451
r5  .13287029
gamma .22140276
beta .04941036
sigma .22794103
IFR_sim .0092533

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1  2.8321382  .00984149   .8980916  .80417644  .04941036
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00001851
r2  .00037027
r3  .00518374
r4  .02497451
r5  .13287029
gamma .22140276
beta .04941036
sigma .22794103
IFR_sim .00925678

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1  2.8321382  .00984149   .8880916  .81417644  .04941036
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00001851
r2  .00037027
r3  .00518374
r4  .02497451
r5  .13287029
gamma .22140276
beta .04941036
sigma .22794103
IFR_sim .00925533

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1  2.8321382  .00984149   .8880916  .80417644  .05941036
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00001851
r2  .00037027
r3  .00518374
r4  .02497451
r5  .13287029
gamma .22140276
beta .05941036
sigma .22794103
IFR_sim .00974619

symmetric vcv[5,5]
            c1          c2          c3          c4          c5
r1   .06702848
r2  -6.096e-06   1.698e-06
r3  -.00359315  -8.097e-06   .00148978
r4  -.00808964  -1.151e-06   .00013043   .00160932
r5  -.00012891  -7.672e-09   1.235e-06   .00001788   2.804e-07
here1

bhat[1,5]
            B          C          D          E          F
r8  2.5083524  .00822653  .89751138  .81635506  .04951205
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00002036
r2  .00040729
r3  .00570211
r4  .02747196
r5  .14615732
gamma .22140276
beta .04951205
sigma .22794103
IFR_sim .01018335
(0 observations deleted)
(191 missing values generated)
(191 missing values generated)
(191 missing values generated)
(191 missing values generated)

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1  2.5183524  .00822653  .89751138  .81635506  .04951205
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00002036
r2  .00040729
r3  .00570211
r4  .02747196
r5  .14615732
gamma .22140276
beta .04951205
sigma .22794103
IFR_sim .0101835

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1  2.5083524  .01822653  .89751138  .81635506  .04951205
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00002036
r2  .00040729
r3  .00570211
r4  .02747196
r5  .14615732
gamma .22140276
beta .04951205
sigma .22794103
IFR_sim .01018111

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1  2.5083524  .00822653  .90751138  .81635506  .04951205
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00002036
r2  .00040729
r3  .00570211
r4  .02747196
r5  .14615732
gamma .22140276
beta .04951205
sigma .22794103
IFR_sim .01018496

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1  2.5083524  .00822653  .89751138  .82635506  .04951205
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00002036
r2  .00040729
r3  .00570211
r4  .02747196
r5  .14615732
gamma .22140276
beta .04951205
sigma .22794103
IFR_sim .0101834

bhat_eps[1,5]
           c1         c2         c3         c4         c5
r1  2.5083524  .00822653  .89751138  .81635506  .05951205
(107 real changes made)
(107 real changes made)

IFR[5,1]
           c1
r1  .00002036
r2  .00040729
r3  .00570211
r4  .02747196
r5  .14615732
gamma .22140276
beta .05951205
sigma .22794103
IFR_sim .01071222

. keep if tin(01Mar2020,$t0_deaths)
(173 observations deleted)

. format date %tdmD

. /*  twoway (rarea dwtot_q33 dwtot_q67 date, fcolor(red%60) lcolor(red%30)) ///
>          (rarea dwtot_q10 dwtot_q90 date, fcolor(red%45) lcolor(red%10)) ///
>          (rarea dwtot_q05 dwtot_q95 date, fcolor(red%30) lcolor(red%10)) ///
>          (tsline wtot_p1 deaths_weekly, lc(cranberry black) lp(l _) ytitle(Thousands)), ///
>              title("Weekly deaths, predicted and actual") legend(off) xtitle("") ///
>              note("67%, 90%, 95% confidence bands. Actual weekly deaths shown in black dashed") tlabel(#10, a
> ngle(45))
>          *graph export "estn/wtot_SE.png", replace
> */
. cap drop reffhat*

. *gen reffhat = 1 + (1/(1/7 + .0007))*((deaths_daily-L7.deaths_daily)/7)/(deaths_weekly/7) 
. gen reffhat = 1 + (1/(1/9.86 + .0007))*((deaths_daily-L7.deaths_daily)/7)/(deaths_weekly/7) // 9.86 = latency
>  period + infectious period in the SIEQRD model
(7 missing values generated)

. lpoly reffhat obsno, bw(14) at(obsno) gen(reffhat_poly) se(reffhat_poly_se) degree(2)

. gen reffhat_poly_q05 = reffhat_poly - 1.96*reffhat_poly_se

. gen reffhat_poly_q95 = reffhat_poly + 1.96*reffhat_poly_se

. 
.   loca nplag = 14 // plot lag of deaths to account for lag in death reporting + longer non-Markov lags in inf
> ections to deaths

.   local vv "reff"

.   twoway (rarea d`vv'_p1_q05 d`vv'_p1_q95 date, fcolor(red%45) lcolor(red%30)) (tsline `vv'_p1 , lc(cranberry
>  ) ) ///
>          (rarea d`vv'_p2_q05 d`vv'_p2_q95 date, fcolor(red%45) lcolor(red%30)) (tsline `vv'_p2 , lc(cranberry
>  ) ) ///
>          (rarea d`vv'_p3_q05 d`vv'_p3_q95 date, fcolor(red%45) lcolor(red%30)) (tsline `vv'_p3 , lc(black    
>  ) ) ///
>          (rarea d`vv'_p4_q05 d`vv'_p4_q95 date, fcolor(red%45) lcolor(red%30)) (tsline `vv'_p4 , lc(cranberry
>  ) ) ///
>          (rarea d`vv'_p5_q05 d`vv'_p5_q95 date, fcolor(red%45) lcolor(red%30)) (tsline `vv'_p5 , lc(cranberry
>  ) ) ///
>          (rarea d`vv'_p6_q05 d`vv'_p6_q95 date, fcolor(red%45) lcolor(red%30)) (tsline `vv'_p6 , lc(cranberry
>  ) ) ///
>          (rarea d`vv'_p7_q05 d`vv'_p7_q95 date, fcolor(red%45) lcolor(red%30)) (tsline `vv'_p7 , lc(cranberry
>  ) ) ///
>          (rarea d`vv'_p8_q05 d`vv'_p8_q95 date, fcolor(red%45) lcolor(red%30)) (tsline `vv'_p8 , lc(cranberry
>  ) ) ///
>                  (rarea F`nplag'.reffhat_poly_q05 F`nplag'.reffhat_poly_q95 date if tin(08Mar2020,05Jul2020),
>  fcolor(teal%60) lcolor(teal%30)) ///
>                  (tsline F`nplag'.reffhat_poly if tin(08Mar2020,05Jul2020), lc(navy) yline(1, lc(black) lp(-)
> ) ), ///
>              title("R-effective: Model and nonparametric estimates") legend(off) xtitle("") ///
>              note("95% confidence bands. Nonparametric estimate is estimated directly from growth rate of dai
> ly" ///
>                      "deaths, smoothed using a local quadratic regression smoother (`nplag' day lag).") tlabe
> l(#10, angle(45))

.           graph export "figs/estn/Reff_SE.png", replace
(note: file figs/estn/Reff_SE.png not found)
(file figs/estn/Reff_SE.png written in PNG format)

. */
. keep dreff_p1_q05 dreff_p1_q95 reff_p1 ///
>          dreff_p2_q05 dreff_p2_q95 reff_p2 ///
>          dreff_p3_q05 dreff_p3_q95 reff_p3 ///
>          dreff_p4_q05 dreff_p4_q95 reff_p4 ///
>          dreff_p5_q05 dreff_p5_q95 reff_p5 ///
>          dreff_p6_q05 dreff_p6_q95 reff_p6 ///
>          dreff_p7_q05 dreff_p7_q95 reff_p7 ///
>          dreff_p8_q05 dreff_p8_q95 reff_p8 ///
>          reffhat_poly reffhat_poly_q05 reffhat_poly_q95 date 

. save "figs/estn/Reff_SE", replace
(note: file figs/estn/Reff_SE.dta not found)
file figs/estn/Reff_SE.dta saved

. 
. log close
      name:  <unnamed>
       log:  C:\Users\jstock\Dropbox\coronavirus\Code\BPEA_replication_code\SEIRD_SEs_v2.txt
  log type:  text
 closed on:  27 Jul 2020, 11:29:28
---------------------------------------------------------------------------------------------------------------
