Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
friosavila committed Mar 14, 2024
1 parent 279e978 commit fc259d7
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 17 deletions.
45 changes: 45 additions & 0 deletions csdid/dipt.ado
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
**program drop dipt
program dipt, eclass

syntax varlist(fv ts) [if] [iw pw fw], [cluster(passthru) from(passthru)]

// ML
gettoken y xvar:varlist
marksample touse

mlexp (`y'*{xb:`xvar' _cons}-(`y'==0)*exp({xb:})) ///
if `touse' [`exp'`weight'], ///
derivative(/xb=`y'-(`y'==0)*exp({xb:})) ///
`from'

end

program dipt0, eclass

syntax varlist(fv ts) [if] [iw pw fw], [cluster(passthru) *]

// ML
gettoken y xvar:varlist
marksample touse

mlexp ({xb:`xvar' _cons}-(`y'==0)*exp({xb:})) ///
if `touse' [`exp'`weight'], ///
derivative(/xb=1-(`y'==0)*exp({xb:})) ///
`options'

end

program dipt1, eclass

syntax varlist(fv ts) [if] [iw pw fw], [cluster(passthru) *]

// ML
gettoken y xvar:varlist
marksample touse

mlexp ({xb:`xvar' _cons}-(`y'==1)*exp({xb:})) ///
if `touse' [`exp'`weight'], ///
derivative(/xb=1-(`y'==1)*exp({xb:})) ///
`options'

end
10 changes: 10 additions & 0 deletions csdid3/csdid2_estat.ado
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*! v1.31 Adds Window.
*! v1.3 Correct with group
*! v1.2 for anticipation
*! v1.1 adds option for CSname
Expand Down Expand Up @@ -59,6 +60,7 @@ end
rgroup(numlist) ///
rcalendar(numlist) ///
revent(numlist) ///
window(numlist min=2 max=2) ///
REBALance(numlist) /// <-- restricts groups and event, unless event is used too
max_mem(real 1) ///
noavg ///
Expand Down Expand Up @@ -111,6 +113,14 @@ end
numlist "`revent'", int
mata:csdidstat.range.selevent=csdidstat.rtokens("`r(numlist)'"):-`adj'
}
else if "`window'"!="" {
numlist "`window'", min(2) max(2) sort integer
local window `r(numlist)'
local n1: word 1 of `window'
local n2: word 2 of `window'
numlist "`n1'/`n2'", int
mata:csdidstat.range.selevent=csdidstat.rtokens("`r(numlist)'"):-`adj'
}
if "`rebalance'"!="" {
numlist "`rebalance'", int
mata:csdidstat.range.selbal=csdidstat.rtokens("`r(numlist)'"):-`adj'
Expand Down
5 changes: 3 additions & 2 deletions jwdid/jwdid.ado
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*!v1.51 Addressed Bug when there is no never treated (but using never)
*!v1.52 Minor Bug. No coeff if not existent
* v1.51 Addressed Bug when there is no never treated (but using never)
* v1.5 Multiple Methods plus extra
* some options not yet documented
* v1.42 Fixes Bug with Continuous Trt
Expand Down Expand Up @@ -194,7 +195,7 @@ program jwdid, eclass
**
foreach i of local glist {
foreach j of local tlist {
qui:count if `i'==`gvar' & `j'==`tvar'
qui:count if `i'==`gvar' & `j'==`tvar' & `touse'
if `r(N)'>0 {
if "`never'"!="" {
if (`i'-`gap')!=`j' {
Expand Down
55 changes: 40 additions & 15 deletions jwdid/jwdid_estat.ado
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*! v1.5 FRA. Fix Bug with Continuous treatment
*! adds PTA test
*! v1.51 FRA. adds Window to event
* v1.5 FRA. Fix Bug with Continuous treatment
* adds PTA test
* v1.42 FRA. flexible PLOT
* v1.41 FRA. Changes | fpr &
* v1.4 FRA. Allows for treatment to be continuous. With ASIS
Expand Down Expand Up @@ -56,16 +57,30 @@ program define jwdid_estat, sortpreserve
}
adde local cmd jwdid
end

**capture program drop jwdid_window
program jwdid_window, rclass
syntax , window(numlist min=2 max=2)
numlist "`window'", min(2) max(2) sort integer
local window `r(numlist)'
local n1: word 1 of `window'
local n2: word 2 of `window'
numlist "`n1'/`n2'", int
return local window `r(numlist)'
end
program define jwdid_simple, rclass
syntax, [* post estore(str) esave(str) replace over(varname) asis PLOT PLOT1(string asis)]
syntax, [* post estore(str) esave(str) replace over(varname) ///
asis PLOT PLOT1(string asis) ///
window(numlist min=2 max=2)]
//tempvar aux
//qui:bysort `e(ivar)':egen `aux'=min(`e(tvar)') if e(sample)
capture:est store `lastreg'
tempname lastreg
capture:qui:est store `lastreg'
tempvar etr
// window

if "`over'"!="" qui: gen `etr'=`over' if !inlist(`over',0,.) & __etr__==1

else local etr
if "`asis'"=="" {
qui:margins , subpop(if __etr__==1) at(__tr__=(0 1)) ///
Expand Down Expand Up @@ -231,39 +246,49 @@ program define jwdid_calendar, rclass
end

program define jwdid_event, rclass
syntax, [post estore(str) esave(str) replace other(varname) PLOT PLOT1(string asis) asis * pretrend ]
syntax, [post estore(str) esave(str) replace other(varname) PLOT PLOT1(string asis) asis * pretrend ///
window(passthru)]
capture drop __event__
tempvar aux
qui:bysort `e(gvar)' `e(ivar)':egen `aux'=min(`e(tvar)') if e(sample)
qui:sum `e(tvar)' if e(sample), meanonly
qui:gen __event__ = `e(tvar)'-`e(gvar)' if `e(gvar)'!=0 & e(sample)

** If window
tempvar sel
gen byte `sel'=1
if "`window'"!="" {
qui:replace `sel'=0
jwdid_window, `window'
local lwind `r(window)'
foreach i of local lwind {
qui:replace `sel'=1 if __event__==`i'
}
}

capture:est store `lastreg'
tempname lastreg
capture:qui:est store `lastreg'
if "`other'"!="" {
*replace __group__=. if inlist(`other',0,.)
local otherif "& !inlist(`other',0,.)"
replace `sel'=0 if inlist(`other',0,.)"
}
*qui:replace __event__ =__event__ - 1 if __event__ <0
if "`e(type)'"=="notyet" {

if "`asis'"=="" {
qui:margins , subpop(if __etr__==1 `otherif') at(__tr__=(0 1)) ///
qui:margins , subpop(if `sel' & __etr__==1 ) at(__tr__=(0 1)) ///
over(__event__) noestimcheck contrast(atcontrast(r)) ///
`options' post
}
else {
qui:margins , subpop(if __etr__==1 `otherif') at(__tr__=0) at((asobserved) __tr__) ///
qui:margins , subpop(if `sel' & __etr__==1 ) at(__tr__=0) at((asobserved) __tr__) ///
over(__event__) noestimcheck contrast(atcontrast(r)) ///
`options' post
}

}
else if "`e(type)'"=="never" {
local nvr = "on"
capture drop __event2__
qui:sum __event__, meanonly
qui:sum __event__ , meanonly
local rmin = r(min)
qui:replace __event__=1+__event__-r(min)
qui:levelsof __event__, local(lv)
Expand All @@ -273,12 +298,12 @@ program define jwdid_event, rclass
label values __event__ __event__
if "`asis'"=="" {
qui:margins , subpop(if __tr__!=0 `otherif') at(__tr__=(0 1)) ///
qui:margins , subpop(if `sel' & __tr__!=0 ) at(__tr__=(0 1)) ///
over(__event__) noestimcheck contrast(atcontrast(r)) ///
`options' post
}
else {
qui:margins , subpop(if __tr__!=0 `otherif') at(__tr__=0) at((asobserved) __tr__) ///
qui:margins , subpop(if `sel' & __tr__!=0 ) at(__tr__=0) at((asobserved) __tr__) ///
over(__event__) noestimcheck contrast(atcontrast(r)) ///
`options' post
}
Expand Down Expand Up @@ -307,7 +332,7 @@ program define jwdid_event, rclass
*** PTA
if "`pretrend'"!="" & "`nvr'"=="on" {
qui:levelsof __event__, local(lv)
qui:levelsof __event__ & `sel' , local(lv)
foreach i of local lv {
if `=-1+`i'+`rmin''<-1 local totest `totest' `i'.__event__
}
Expand Down

0 comments on commit fc259d7

Please sign in to comment.