Dialysis

This package contains functions useful for reproducing Grieco & McDevitt (2017). See this assignment 1 and 2.

Function Reference

Dialysis.clustercovMethod
clustercov(x::Array{Real,2}, clusterid)

Compute clustered, heteroskedasticity robust covariance matrix estimate for Var(∑ x). Assumes that observations with different clusterid are independent, and observations with the same clusterid may be arbitrarily correlated. Uses number of observations - 1 as the degrees of freedom.

Arguments

  • x number of observations by dimension of x matrix
  • clusterid number of observations length vector

Returns

  • V dimension of x by dimension of x matrix
source
Dialysis.downloadDFRMethod
downloadDFR(;redownload=false)

Downloads Dialysis Facility Reports. Saves zipfiles in Dialysis/data/.

source
Dialysis.errors_gmMethod
errors_gm(y::Symbol, k::Symbol, l::Symbol, Φ::Symbol,
               id::Symbol, t::Symbol, data::DataFrame;
               npregress::Function=polyreg)

Returns functions that given β calculate ω(β) and η(β).

Arguments

  • y Symbol for y variable in data
  • k Symbol for k variable in data
  • l Symbol for l variable in data
  • q Symbol for q variable in data
  • Φ Symbol for Φ variable in data
  • id Symbol for id variable in data
  • t Symbol for t variable in data
  • data DataFrame containing variables
  • α estimate of α

Returns

  • ωfunc(β) computes ω given β for the data and α passed in as input. length(ωfunc(β)) == nrow(data) ωfunc(β) will contain missings if the data does.
  • ηfunc(β) computes η given β. for the data and α passed in as input. length(ηfunc(β)) == nrow(data) ηfunc(β) will contain missings.

Warning: this function is not thread safe!

source
Dialysis.loadDFRMethod
loadDFR(;recreate=false)

If Dialysis/data/dfr.zip exists, load it from disk. Otherwise, create Dialysis/data/dfr.zip exists by loading Dialysis Facility Reports from zipfiles in Dialysis/data/.

source
Dialysis.locallinearMethod
locallinear(xpred::AbstractMatrix,
            xdata::AbstractMatrix,
            ydata::AbstractMatrix)

Computes local linear regression of ydata on xdata. Returns predicted y at x=xpred. Uses Scott's rule of thumb for the bandwidth and a Gaussian kernel. xdata should not include an intercept.

Arguments

  • xpred x values to compute fitted y
  • xdata observed x
  • ydata observed y, must have size(y)[1] == size(xdata)[1]
  • bandwidth_multiplier multiply Scott's rule of thumb bandwidth by this number

Returns

  • Estimates of f(xpred)
source
Dialysis.objective_gmMethod
objective_gm(y::Symbol,  k::Symbol, l::Symbol, q::Symbol,
                  Φ::Symbol, id::Symbol, t::Symbol,
                  instruments::Array{Symbol,1}, data::DataFrame
                  ; W=UniformScaling(1.),
                  npregress::Function=(xp,xd,yd)->polyreg(xp,xd,yd,degree=1))
source
Dialysis.panellagFunction
panellag(x::Symbol, data::AbstractDataFrame, id::Symbol, t::Symbol,
          lags::Integer=1)

Create lags of variables in panel data.

Arguments

  • x variable to create lag of
  • data DataFrame containing x, id, and t
  • id cross-section identifier
  • t time variable
  • lags number of lags. Can be negative, in which cause leads will be created

Returns

  • A vector containing lags of data[x]. Will be missing for id and t combinations where the lag is not contained in data.
source
Dialysis.partiallinearMethod

function partiallinear(y::Symbol, x::Array{Symbol, 1}, controls::Array{Symbol,1}, data::DataFrame; npregress::Function=polyreg, clustervar::Symbol=Symbol())

Estimates a partially linear model. That is, estimate

\[ y = xβ + f(controls) + ϵ\]

Assuming that E[ϵ|x, controls] = 0.

Arguments

  • y symbol specificying y variable
  • x
  • controls list of control variables entering f
  • data DataFrame where all variables are found
  • npregress function for estimating E[w|x] nonparametrically. Used to partial out E[y|controls] and E[x|controls] and E[q|controls].
  • clustervar symbol specifying categorical variable on which to cluster when calculating standard errors

Returns

  • regression output from FixedEffectModels.jl

Details

Uses orthogonal (with respect to f) moments to estimate β. In particular, it uses

\[0 = E[(y - E[y|controls]) - (x - E[x|controls])β)*(x - E[x|controls])]\]

to estimate β. In practice this can be done by regressing (y - E[y|controls]) on (x - E[x|controls]). FixedEffectModels is used for this regression. Due to the orthogonality of the moment condition the standard errors on β will be the same as if E[y|controls] and E[x|controls] were observed (i.e. FixedEffectModels will report valid standard errors)

source
Dialysis.partiallinearIVMethod
  partiallinearIV(y::Symbol, q::Symbol, z::Symbol,
                  controls::Array{Symbol,1}, data::DataFrame;
                  npregress::Function)

Estimates a partially linear model using IV. That is, estimate

y = αq + Φ(controls) + ϵ

using z as an instrument for q with first stage

q = h(z,controls) + u

It assumes that E[ϵ|z, controls] = 0.

Uses orthogonal (wrt Φ and other nuisance functions) moments for estimating α. In particular, it uses

0 = E[(y - E[y|controls] - α(q - E[q|controls]))*(E[q|z,controls] - E[q|controls])]

See section 4.2 (in particular footnote 8) of Chernozhukov, Chetverikov, Demirer, Duflo, Hansen, Newey, and Robins (2018) for more information.

In practice α can be estimated by an iv regression of (y - E[y|controls]) on (q - E[q|controls]) using (E[q|z,controls] - E[q|controls]) as an instrument. FixedEffectModels is used for this regression. Due to the orthogonality of the moment condition, the standard error on α will be the same as if E[y|controls] and E[q|controls] were observed (i.e. FixedEffectModels will report valid standard errors)

Arguments

  • y symbol specificying y variable
  • q
  • z list of instruments
  • controls list of control variables entering Φ
  • data DataFrame where all variables are found
  • npregress function for estimating E[w|x] nonparametrically. Used to partial out E[y|controls], E[q|z,controls], and E[q|controls]. Syntax should be the same as locallinear or polyreg

Returns

  • α estimate of α
  • Φ estimate of Φ(controls)
  • regest regression output with standard error for α
source
Dialysis.polyregMethod
  polyreg(xpred::AbstractMatrix,
          xdata::AbstractMatrix,
          ydata::AbstractMatrix; degree=1)

Computes polynomial regression of ydata on xdata. Returns predicted y at x=xpred.

Arguments

  • xpred x values to compute fitted y
  • xdata observed x
  • ydata observed y, must have size(y)[1] == size(xdata)[1]
  • degree
  • deriv whether to also return df(xpred). Only implemented when xdata is one dimentional

Returns

  • Estimates of f(xpred)
source