admin 管理员组

文章数量: 1086019


2024年12月29日发(作者:c语言源程序)

Package‘didimputation’

October13,2022

TypePackage

TitleImputationEstimatorfromBorusyak,Jaravel,andSpiess(2021)

Version0.3.0

DescriptionEstimatesTwo-wayFixedEffectsdifference-in-differences/event-

studymodelsusingtheimputation-

basedapproachproposedbyBorusyak,Jaravel,andSpiess(2021).

EncodingUTF-8

LazyDatatrue

RoxygenNote7.2.1

LinkingToRcpp,RcppArmadillo

DependsR(>=2.10),fixest(>=0.10.0),(>=1.10.0)

ImportsMatrix,magrittr,Rcpp,broom,dplyr,glue,stringr,purrr,

tidyr

Suggestshaven,testthat(>=3.0.0)

Config/testthat/edition3

LicenseMIT+fileLICENSE

NeedsCompilationyes

AuthorKyleButts[aut,cre]()

MaintainerKyleButts<***********************>

RepositoryCRAN

Date/Publication2022-08-2520:02:33UTC

Rtopicsdocumented:

.

Index

1

2

2

3

6

2df_hom

df_hetSimulateddatawithtwotreatmentgroupsandheterogenouseffects

Description

Generatedusingthefollowingcall:did2s::gen_data(panel=c(1990,2020),g1=2000,g2=

2010,g3=0,te1=2,te2=1,te3=0,te_m1=0.05,te_m2=0.15,te_m3=0)

Usage

df_het

Format

Adataframewith31000rowsand15variables:

unitindividualinpaneldata

yeartimeinpaneldata

gtheyearthattreatmentstarts

dep_varoutcomevariable

treatT/Fvariableforwhentreatmentison

rel_=nevertreated.

rel_year_binnedyearrelativetotreatmentstart,but<=-6and>=6arebinned.

unit_feUnitFE

year_feYearFE

errorRandomerrorcomponent

teStatictreatmenteffect=te

te_dynamicDynamictreatmeteffect=te_m

stateStatethatunitisin

groupStringnameforgroup

df_homSimulateddatawithtwotreatmentgroupsandhomogenouseffects

Description

Generatedusingthefollowingcall:did2s::gen_data(panel=c(1990,2020),g1=2000,g2=

2010,g3=0,te1=2,te2=2,te3=0,te_m1=0,te_m2=0,te_m3=0)

Usage

df_hom

did_imputation

Format

Adataframewith31000rowsand15variables:

unitindividualinpaneldata

yeartimeinpaneldata

gtheyearthattreatmentstarts

dep_varoutcomevariable

treatT/Fvariableforwhentreatmentison

rel_=nevertreated.

rel_year_binnedyearrelativetotreatmentstart,but<=-6and>=6arebinned.

unit_feUnitFE

year_feYearFE

errorRandomerrorcomponent

teStatictreatmenteffect=te

te_dynamicDynamictreatmeteffect=te_m

groupStringnameforgroup

stateStatethatunitisin

weightWeightfromrunif()

3

did_imputationBorusyak,Jaravel,andSpiess(2021)Estimator

Description

Treatmenteffectestimationandpre-trendtestinginstaggeredadoptiondiff-in-diffdesignswithan

imputationapproachofBorusyak,Jaravel,andSpiess(2021)

Usage

did_imputation(

data,

yname,

gname,

tname,

idname,

first_stage=NULL,

wname=NULL,

wtr=NULL,

horizon=NULL,

pretrends=NULL,

cluster_var=NULL

)

4

Arguments

data

yname

gname

tname

idname

first_stage

wname

wtr

horizon

did_imputation

estc()syntaxformultiplelhs.

lenameforunit-specificdateoftreatment(never-treatedshould

bezeroorNA).

lenameforcalendarperiod.

lenameforuniqueunitid.

FormulaforY(0).Formulafollowingfixest::ffectsspecified

after"|".Ifnotspecified,thenjustunitandtimefixedeffectswillbeused.

usedin

estimatingY(0)andalsoaugmentstreatmenteffectweights.

Charactervectoroftreatmentweightnames(seehorizonforstandardstaticand

event-studyweights)

Integervectorofevent_lyappliesifwtrisleftasNULL.

ifspecified,weightedaverages/sumsoftreatmenteffectswillbereportedfor

eachofthesehorizonsseparately(0forthetreatmentperiod,tau1forone

periodaftertreatment,etc.).IfTRUE,ndhorizon

arenull,thenthestatictreatmenteffectiscalculated.

,allpretrendsare

used.

upplied,thenidnameisused

asdefault.

pretrends

cluster_var

Details

Theimputation-basedestimatorisamethodofcalculatingtreatmenteffectsinadifference-in-

hodestimatesamodelforY(0)usinguntreated/not-yet-treated

observationsandpredictsY(0)forthetreatedobservationshat(Y_it(0)).Thedifferencebetween

treatedandpredicteduntreatedoutcomesY_it(1)-hat(Y_it(0))servesasanestimateforthetreat-

rethenaveragedtoformaveragetreatmenteffectsfor

groupsofit.

Value

ontainingtreatmenteffectterm,estimate,standarderrorandconfidenceinterval.

Thisisintidyformat.

Examples

Loadexampledatasetwhichhastwotreatmentgroupsandhomogeneoustreatmenteffects

#LoadExampleDataset

data("df_hom",package="did2s")

StaticTWFE:

YoucanrunastaticTWFEfixedeffectmodelforasimpletreatmentindicator

did_imputation

did_imputation(data=df_hom,yname="dep_var",gname="g",

tname="year",idname="unit")

#>#Atibble:1x6

#>

#>

#>1dep_vartreat2.000.01821.972.04

EventStudy:

Oryoucanuserelative-treatmentindicatorstoestimateaneventstudyestimate

did_imputation(data=df_hom,yname="dep_var",gname="g",

tname="year",idname="unit",horizon=TRUE)

#>#Atibble:21x6

#>

#>

#>1dep_var01.970.04251.892.05

#>2dep_var12.050.04341.972.14

#>3dep_var22.030.04321.952.12

#>4dep_var31.970.04281.882.05

#>5dep_var41.970.04201.882.05

#>6dep_var52.030.04231.952.11

#>7dep_var62.040.04501.952.13

#>8dep_var72.000.04371.912.08

#>9dep_var82.020.04401.932.10

#>10dep_var91.960.04401.872.04

#>#...with11morerows

ExamplefromChengandHoekstra(2013):

Here’sanexampleusingdatafromChengandHoekstra(2013)

5

#CastleData

castle<-haven::read_dta("/scunning1975/mixtape/raw/master/")

did_imputation(data=castle,yname="c(l_homicide,l_assault)",gname="effyear",

first_stage=~0|sid+year,

tname="year",idname="sid")

#>#Atibble:2x6

#>

#>

#>1l_homicidetreat0.07980.0609-0.03950.199

#>2l_assaulttreat0.04960.0513-0.05100.150

Index

∗datasets

df_het,2

df_hom,2

df_het,2

df_hom,2

did_imputation,3

fixest::feols,4

6


本文标签: 语言 源程序 作者