wfe(wfe)
wfe()所属R语言包:wfe
Fitting the Weighted Fixed Effects Model for Causal Inference
拟合加权固定效应模型的推论
译者:生物统计家园网 机器人LoveR
描述----------Description----------
wfe is used to fit weighted fixed effects model for causal inference. wfe also derives the regression weights for different causal quantity of interest.
wfe来拟合加权固定效应模型进行因果推理。 wfe也派生的回归权重不同的因果数量利益。
用法----------Usage----------
wfe(formula, data, treat = "treat.name",
unit.index, time.index = NULL, method = "unit",
qoi = c("ate", "att") , estimator = NULL, C.it = NULL,
hetero.se = TRUE, auto.se = TRUE,
White = TRUE, White.alpha = 0.05,
verbose = TRUE, unbiased.se = FALSE, unweighted = FALSE,
rank.check = FALSE, tol = sqrt(.Machine$double.eps))
参数----------Arguments----------
参数:formula
a symbolic description of the model to be fitted. The formula should not include dummmies for fixed effects. The details of model specifications are given under "Details".
安装一个象征性的模型来描述。公式不应该包括固定效应dummmies为。型号规格的详细信息刊载在“详细信息”。
参数:data
data frame containing the variables in the model.
数据框包含在模型中的变量。
参数:treat
a character string indicating the name of treatment variable used in the models. The treatment should be binary indicator (integer with 0 for the control group and 1 for the treatment group).
一个字符串,指示处理变量在模型中使用的名称。治疗指标应该是二进制的(整数为治疗组与对照组为0和1)。
参数:unit.index
a character string indicating the name of unit variable used in the models. The index of unit should be factor.
一个字符串,表示单位在模型中使用的变量的名称。单位应该是该指数的因素。
参数:time.index
a character string indicating the name of time variable used in the models. The index of time should be factor.
一个字符串表示模型所用的时间变量的名称。该指数的时间应的因素。
参数:method
method for weighted fixed effects regression, either unit for unit fixed effects; time for time fixed effects. The default is unit.
加权固定效应回归的方法,无论是unit为单位的固定效应,“time时间固定效应。默认的unit。
参数:qoi
one of "ate" or "att". The default is "ate".
一个"ate"或"att"。默认的"ate"。
参数:estimator
an optional character string indicating the estimating method. One of "fd" or "did". The default is NULL.
一个可选的字符串表示的估计方法。一个"fd"或"did"。默认的NULL。
参数:C.it
an optional non-negative numeric vector specifying relative weights for each unit of analysis.
一个可选的非负数值的相对权重向量确定各单位的分析。
参数:hetero.se
a logical value indicating whether heteroskedasticity across units is allowed in calculating standard errors. The default is TRUE.
一个逻辑值,该值指示是否允许异方差性跨部门的计算标准误差。默认的TRUE。
参数:auto.se
a logical value indicating whether arbitrary autocorrelation is allowed in calculating standard errors. The default is TRUE.
一个逻辑值,该值指示是否允许任意的自相关计算标准误差。默认的TRUE。
参数:White
a logical value indicating whether White misspecification statistics should be calculated. The default is TRUE.
一个逻辑值,该值指示是否应计算白误设统计。默认的TRUE。
参数:White.alpha
level of functional specification test. See White (1980) and Imai and Kim (2012). The default is 0.05.
功能规格测试的水平。请参阅白皮书(1980年)和今井和Kim(2012年)。默认的0.05。
参数:verbose
logical. If TRUE, helpful messages along with a progress report of the weight calculation are printed on the screen. The default is TRUE.
逻辑。如果TRUE,有用的信息以及权重计算的进度报告显示在屏幕上。默认的TRUE。
参数:unbiased.se
logical. If TRUE, bias-asjusted heteroskedasticity-robust standard errors are used. See Stock and Watson (2008). Should be used only for balanced panel. The default is FALSE.
逻辑。如果TRUE,偏置asjusted异方差稳健标准误差所使用。 Stock和Watson(2008年)。应仅用于平衡面板。默认的FALSE。
参数:unweighted
logical. If TRUE, standard unweighted fixed effects model is estimated. The default is FALSE.
逻辑。如果TRUE,标准不加权的固定效应模型估计。默认的FALSE。
参数:rank.check
logical. If TRUE, rank condition is checked for fast calculation with projection method. The default is FALSE.
逻辑。如果TRUE,秩条件检查投影方法的快速计算。默认的FALSE。
参数:tol
a relative tolerance to detect zero singular values for generalized inverse. The default is sqrt(.Machine$double.eps)
一个相对宽容的检测广义逆的奇异值为零。默认值是开方机(double.eps)
Details
详细信息----------Details----------
To fit the weighted unit (time) fixed effects model, use the syntax for the formula, y ~ x1 + x2, where y is a dependent variable and x1 and x2 are unit (time) varying covariates.
为了适应固定效应模型的加权单位(时间),使用的语法的公式,y ~ x1 + x2,y是一个因变量,x1和x2单位(时间)变化的协变量。
wfe calculates weights based on different underlying causal quantity of interest: Average Treatment Effect (qoi = "ate") or Average Treatment Effect for the Treated (qoi = "att").
wfe计算的权重根据不同的基础因果关系的关注量:一般治疗效果(qoi = "ate")或平均治疗效果的治疗(qoi = "att")。
One can further set estimating methods: First-Difference (estimator ="fd") or Difference-in-differences (estimator = "did"). For the two-way fixed effects model, set estimator = "did"
我们可以进一步设置估算方法:一阶差分(estimator ="fd")或差的差异(estimator = "did")。对于双向固定效应模型,设置estimator = "did"
To specify different ex-ante weights for each unit of analysis, use non-negative weights C.it. For instance, using the survey weights for C.it enables the estimation fo the average treatement effect for the target population.
要指定不同的权重事前各单位的分析,使用非负权重C.it。例如,使用的调查权重为C.it使估计为的平均treatement影响的目标人群。
An object of class "wfe" contains vectors of unique unit(time) names and unique unit(time) indices.
“WFE”类的一个对象包含向量的独特的单位(时间)的名称和独特的单位(时间)指数。
值----------Value----------
wfe returns an object of class "wfe", a list that contains the components listed below.
wfe返回一个对象类“WFE”,一个列表,包含以下列出的组件。
The function summary (i.e., summary.wfe) can be used to obtain a table of the results.
该函数summary(即,summary.wfe)可以用来获得的结果的表。
参数:coefficients
a named vector of coefficients
一个命名的系数向量
参数:residuals
the residuals, that is respons minus fitted values
残差,即反应作者减去拟合值
参数:df
the degree of freedom
的自由度
参数:W
weight matrix calculated from the model. Row and column indices can be found from unit.name, time.name.
模型计算出的权重矩阵。行和列索引,可以发现从unit.name,time.name。
参数:call
the matched call
匹配的呼叫
参数:causal
causal quantity of interest
因果数量利益
参数:estimator
the estimating method
估算方法
参数:unit.name
a vector containing unique unit names
一个向量,包含独特的单位名称
参数:unit.index
a vector containing unique unit index number
一个向量,包含独特的单位索引号
参数:time.name
a vector containing unique time names
一个向量,包含独特的时间名称
参数:time.index
a vector containing unique time index number
一个向量,包含独特的时间索引号
参数:method
call of the method used
要求所使用的方法
参数:vcov
the variance covariance matrix
方差协方差矩阵
参数:White.alpha
the alpha level for White specification test
白规格测试的alpha水平
参数:White.pvalue
the p-value for White specification test
白规格测试的p值
参数:White.stat
the White statistics
白统计
参数:x
the design matrix
设计矩阵
参数:y
the response vector
响应矢量
参数:mf
the model frame
模型框架
(作者)----------Author(s)----------
Kosuke Imai, Princeton University, <a href="mailto:kimai@princeton.edu">kimai@princeton.edu</a>
and In Song Kim, Princeton University, <a href="mailto:insong@princeton.edu">insong@princeton.edu</a>
参考文献----------References----------
Effects Regression Models for Causal Inference.” Technical Report, Department of Politics, Princeton University. available at http://imai.princeton.edu/research/FEmatch.html
Standard Errors for Fixed Effect Panel Data Regression” Econometrica, 76, 1.
Regression Functions.” International Economic Review, 21, 1, 149–170.
参见----------See Also----------
pwfe for fitting weighted fixed effects models with propensity score weighting
pwfe倾向评分加权拟合加权固定效应模型
实例----------Examples----------
### NOTE: this example illustrates the use of wfe function with randomly[##注意:这个例子说明了随机的WFE功能与使用]
### generated panel data with arbitrary number of units and time.[##生成任意数量的面板数据单位和时间。]
## generate panel data with number of units = N, number of time = Time[#生成面板数据的单位数= N,时间=时间]
N <- 10 # number of distinct units[不同的单元的数量]
Time <- 15 # number of distinct time[不同的时间的数量]
## treatment effect[#治疗效果]
beta <- 1
## generate treatment variable[#生成处理变量]
treat <- matrix(rbinom(N*Time, size = 1, 0.25), ncol = N)
## make sure at least one observation is treated for each unit[#确保每个单元至少一个观察治疗]
while ((sum(apply(treat, 2, mean) == 0) > 0) | (sum(apply(treat, 2, mean) == 1) > 0) |
(sum(apply(treat, 1, mean) == 0) > 0) | (sum(apply(treat, 1, mean) == 1) > 0)) {
treat <- matrix(rbinom(N*Time, size = 1, 0.25), ncol = N)
}
treat.vec <- c(treat)
## unit fixed effects[#机组固定效应]
alphai <- rnorm(N, mean = apply(treat, 2, mean))
## geneate two random covariates[#geneate两个随机协变量]
x1 <- matrix(rnorm(N*Time, 0.5,1), ncol=N)
x2 <- matrix(rbeta(N*Time, 5,1), ncol=N)
x1.vec <- c(x1)
x2.vec <- c(x2)
## generate outcome variable[#产生的结果变量]
y <- matrix(NA, ncol = N, nrow = Time)
for (i in 1:N) {
y[, i] <- alphai[i] + treat[, i] + x1[,i] + x2[,i] + rnorm(Time)
}
y.vec <- c(y)
## generate unit and time index[#生成单元和时间指数]
unit.index <- rep(1:N, each = Time)
time.index <- rep(1:Time, N)
Data.str <- as.data.frame(cbind(y.vec, treat.vec, unit.index, x1.vec, x2.vec))
colnames(Data.str) <- c("y", "tr", "strata.id", "x1", "x2")
Data.obs <- as.data.frame(cbind(y.vec, treat.vec, unit.index, time.index, x1.vec, x2.vec))
colnames(Data.obs) <- c("y", "tr", "unit", "time", "x1", "x2")
############################################################[################################################## #########]
# Example 1: Stratified Randomized Experiments[例1:采用分层随机试验]
############################################################[################################################## #########]
## run the weighted fixed effect regression with strata fixed effect.[#运行的加权固定效应回归与地层固定作用。]
## Note: the quantity of interest is Average Treatment Effect ("ate")[注:关注量平均处理效果(“吃”)]
## and the standard errors allow heteroskedasticity and arbitrary[#和标准误差允许异方差和任意]
## autocorrelation.[#自相关。]
### Average Treatment Effect[##平均处理效果]
mod.ate <- wfe(y~ tr+x1+x2, data = Data.str, treat = "tr",
unit.index = "strata.id", method = "unit",
qoi = "ate", hetero.se=TRUE, auto.se=TRUE)
## summarize the results[#总结的结果。]
summary(mod.ate)
### Average Treatment Effect for the Treated[##平均处理后的治疗效果]
mod.att <- wfe(y~ tr+x1+x2, data = Data.str, treat = "tr",
unit.index = "strata.id", method = "unit",
qoi = "att", hetero.se=TRUE, auto.se=TRUE)
## summarize the results[#总结的结果。]
summary(mod.att)
############################################################[################################################## #########]
# Example 2: Observational Studies with Unit Fixed-effects[例2:单位固定效应的观测研究]
############################################################[################################################## #########]
## run the weighted fixed effect regression with unit fixed effect.[#执行单位固定效应的加权固定效应回归。]
## Note: the quantity of interest is Average Treatment Effect ("ate")[注:关注量平均处理效果(“吃”)]
## and the standard errors allow heteroskedasticity and arbitrary[#和标准误差允许异方差和任意]
## autocorrelation.[#自相关。]
mod.obs <- wfe(y~ tr+x1+x2, data = Data.obs, treat = "tr",
unit.index = "unit", time.index = "time", method = "unit",
qoi = "ate", hetero.se=TRUE, auto.se=TRUE,
White = TRUE, White.alpha = 0.05)
## summarize the results[#总结的结果。]
summary(mod.obs)
## extracting weigths[#提取weigths]
summary(mod.obs)$W
###################################################################[################################################## ################]
# Example 3: Observational Studies with differences-in-differences[例3:观察性研究的差异,在差异]
###################################################################[################################################## ################]
## run difference-in-differences estimator.[#运行差异,差异的估计。]
## Note: the quantity of interest is Average Treatment Effect ("ate")[注:关注量平均处理效果(“吃”)]
## and the standard errors allow heteroskedasticity and arbitrary[#和标准误差允许异方差和任意]
## autocorrelation.[#自相关。]
mod.did <- wfe(y~ tr+x1+x2, data = Data.obs, treat = "tr",
unit.index = "unit", time.index = "time", method = "unit",
qoi = "ate", estimator ="did", hetero.se=TRUE, auto.se=TRUE,
White = TRUE, White.alpha = 0.05, verbose = TRUE)
## summarize the results[#总结的结果。]
summary(mod.did)
## extracting weigths[#提取weigths]
summary(mod.did)$W
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|