Title: | Simple function to adjust for covariates in synthdid |
---|---|
Description: | Simple function to adjust for covariates in synthdid. See vignete for details. |
Authors: | Sebastian Kranz |
Maintainer: | Sebastian Kranz <[email protected]> |
License: | GPL >= 3.0 |
Version: | 0.1.0 |
Built: | 2024-12-08 02:59:34 UTC |
Source: | https://github.com/skranz/xsynthdid |
Implements a way to adjust the outcome varible for additional covariates x. The adjusted outcome can be used for a synthdid estimate that accounts for the covariates. More precisely, you can use the name of the new adjusted outcome (by default "y.adj") as argument outcome in your call to panel.matrices that prepares the data for synthdid_estimate. See the Vignete for an example.
adjust.outcome.for.x( panel, unit = 1, time = 2, outcome = 3, treatment = 4, x, x.rows = NULL, add.mean = FALSE )
adjust.outcome.for.x( panel, unit = 1, time = 2, outcome = 3, treatment = 4, x, x.rows = NULL, add.mean = FALSE )
panel |
A data frame with columns consisting of units, time, outcome, and treatment indicator. It should be a balanced panel and not contain any NA. |
unit |
The column number/name corresponding to the unit identifier. Default is 1. |
time |
The column number/name corresponding to the time identifier. Default is 2. |
outcome |
The column number/name corresponding to the outcome identifier. Default is 3. |
treatment |
The column number/name corresponding to the treatment status. Default is 4. |
x |
The column numbers/names of all additional control variables |
x.rows |
To estimate the effect of x on y, we use by default all rows in which no treatment takes places. The argument x.rows allows to specify these rows manually. E.g. you could only take all rows before the first treatment starts (i.e. compared to the default exclude the rows of the control group during the treatment period). |
add.mean |
Shall the average of the effect of x on the outcome over all observatios be added to the outcome? If TRUE, the mean of the adjusted outcome is the same as the mean of the original outcome. Default is FALSE. |
The computed adjusted values for y. They can be used as outcome column in a subsequent call to panel.matrices in order to then estimate synthdid adjusted for the control variables that where specified here in x.
Calls adjust.outcome.for.y, panel.matrices and then synthdid_estimate. Has similar syntax to xsdid_se_bootstrap.
xsdid_estimate( panel, unit = 1, time = 2, outcome = 3, treatment = 4, x, x.rows = NULL )
xsdid_estimate( panel, unit = 1, time = 2, outcome = 3, treatment = 4, x, x.rows = NULL )
panel |
A data frame with columns consisting of units, time, outcome, and treatment indicator. It should be a balanced panel and not contain any NA. |
unit |
The column number/name corresponding to the unit identifier. Default is 1. |
time |
The column number/name corresponding to the time identifier. Default is 2. |
outcome |
The column number/name corresponding to the outcome identifier. Default is 3. |
treatment |
The column number/name corresponding to the treatment status. Default is 4. |
x |
The column numbers/names of all additional control variables |
x.rows |
To estimate the effect of x on y, we use by default all rows in which no treatment takes places. The argument x.rows allows to specify these rows manually. E.g. you could only take all rows before the first treatment starts (i.e. compared to the default exclude the rows of the control group during the treatment period). |
The resulting object from the call to synthdid_estimate.
## Not run: dat = xsdid.mc(N=20, T=20,return.data = TRUE) xsdid_estimate(dat, unit="i",time = "t",outcome = "y",treatment = "treat_exp",x = "x") xsdid_se_bootstrap(dat, unit="i",time = "t",outcome = "y",treatment = "treat_exp",x = "x", B=100)$se ## End(Not run)
## Not run: dat = xsdid.mc(N=20, T=20,return.data = TRUE) xsdid_estimate(dat, unit="i",time = "t",outcome = "y",treatment = "treat_exp",x = "x") xsdid_se_bootstrap(dat, unit="i",time = "t",outcome = "y",treatment = "treat_exp",x = "x", B=100)$se ## End(Not run)
Each clustered bootstrap sample is a sample of units with replacement. It is guranteed that at least 2 treatment group and at least 2 control group units are selected. (Ideally at least 1 of each should suffice but just a single observation in a group can lead to downstream errors when calling synthdid_estimate. This issue needs to be explored further)
xsdid_se_bootstrap( panel, unit = 1, time = 2, outcome = 3, treatment = 4, x, B = 100, num.cores = 1 )
xsdid_se_bootstrap( panel, unit = 1, time = 2, outcome = 3, treatment = 4, x, B = 100, num.cores = 1 )
panel |
A data frame with columns consisting of units, time, outcome, and treatment indicator. It should be a balanced panel and not contain any NA. |
unit |
The column number/name corresponding to the unit identifier. Default is 1. |
time |
The column number/name corresponding to the time identifier. Default is 2. |
outcome |
The column number/name corresponding to the outcome identifier. Default is 3. |
treatment |
The column number/name corresponding to the treatment status. Default is 4. |
x |
The column numbers/names of all additional control variables |
B |
number of bootstrap samples (Default 100). |
num.cores |
if larger than 1 use the parallel package to perform the bootstrap estimation on multiple cores. (More than 1 core does not work on Windows.) |
In each bootstrap sample, we use the function adjust.outcome.for.x to adjust for the covariates.
As list with 2 elements: - se is the estimated standard error of the treatment effect tau. - boot.tau is a vector containing the estimated treatment effects tau for each bootstrap replication.
## Not run: dat = xsdid.mc(N=20, T=20,return.data = TRUE) xsdid_estimate(dat, unit="i",time = "t",outcome = "y",treatment = "treat_exp",x = "x") xsdid_se_bootstrap(dat, unit="i",time = "t",outcome = "y",treatment = "treat_exp",x = "x", B=100)$se ## End(Not run)
## Not run: dat = xsdid.mc(N=20, T=20,return.data = TRUE) xsdid_estimate(dat, unit="i",time = "t",outcome = "y",treatment = "treat_exp",x = "x") xsdid_se_bootstrap(dat, unit="i",time = "t",outcome = "y",treatment = "treat_exp",x = "x", B=100)$se ## End(Not run)
For details look at the code. For an illustration see the vignette.
xsdid.mc( N = 100, T = 200, tau = 50, beta.tt = 50, beta.x = 50, beta.xc = 0, beta.treat = 50, x.tt.load = 0, xc.x.load = 0, x.treat.load.mean = 3/4, x.contr.load.mean = 1/4, x.load.alpha.beta = 2, xc.treat.load.mean = 3/4, xc.contr.load.mean = 1/4, xc.load.alpha.beta = 2, ar = 0.97, ar.tt = ar, ar.x = ar, ar.xc = ar, return.data = FALSE )
xsdid.mc( N = 100, T = 200, tau = 50, beta.tt = 50, beta.x = 50, beta.xc = 0, beta.treat = 50, x.tt.load = 0, xc.x.load = 0, x.treat.load.mean = 3/4, x.contr.load.mean = 1/4, x.load.alpha.beta = 2, xc.treat.load.mean = 3/4, xc.contr.load.mean = 1/4, xc.load.alpha.beta = 2, ar = 0.97, ar.tt = ar, ar.x = ar, ar.xc = ar, return.data = FALSE )