From b51145f63f01f6819b22c5ca399c98b6b3f87b81 Mon Sep 17 00:00:00 2001 From: Fernando Rios-Avila <78816534+friosavila@users.noreply.github.com> Date: Wed, 24 Apr 2024 13:11:33 -0400 Subject: [PATCH] s s --- jwdid/jwdid_estat.ado | 16 +++++++++++- jwdid/jwdid_plot.ado | 16 ++++++------ jwdid/unit_test.do | 60 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 9 deletions(-) create mode 100644 jwdid/unit_test.do diff --git a/jwdid/jwdid_estat.ado b/jwdid/jwdid_estat.ado index ae89916..33db74e 100644 --- a/jwdid/jwdid_estat.ado +++ b/jwdid/jwdid_estat.ado @@ -1,4 +1,5 @@ -*! v1.71 FRA. Bug with Pretrend +*! v1.72 FRA. Anticipation without Never +* v1.71 FRA. Bug with Pretrend * v1.7 FRA. Fixes how to Store Table (with new names) * v1.6 FRA. Fixes to esave, and Orestriction * v1.51 FRA. adds Window to event @@ -317,6 +318,19 @@ program define jwdid_event, rclass *qui:replace __event__ =__event__ - 1 if __event__ <0 if "`e(type)'"=="notyet" { +**** + local nvr = "on" + capture drop __event2__ + qui:sum __event__ , meanonly + local rmin = r(min) + qui:replace __event__=1+__event__-r(min) + qui:levelsof __event__, local(lv) + foreach i of local lv { + label define __event__ `i' "`=-1+`i'+`rmin''", modify + } + label values __event__ __event__ + +**** if "`asis'"=="" { qui:margins [`weight'`exp'], subpop(if `sel' & __etr__==1 & `tosel') at(__tr__=(0 1)) /// over(__event__) noestimcheck contrast(atcontrast(r)) /// diff --git a/jwdid/jwdid_plot.ado b/jwdid/jwdid_plot.ado index a0d1b6c..69a2e79 100644 --- a/jwdid/jwdid_plot.ado +++ b/jwdid/jwdid_plot.ado @@ -116,7 +116,7 @@ program jwdid_plot_wh qui:replace `kk'="`i'" in `k' } tempname k2 - qui:encode `kk', gen(`k2') + qui:destring `kk', gen(`k2') jwdid_plot_group `k2' `mm1' `mm5' `mm6' , /// `style' `title' `name' `ytitle' `xtitle' `legend' `options' @@ -145,7 +145,7 @@ program jwdid_plot_wh qui:replace `kk'="`i'" in `k' } tempname k2 - qui:encode `kk', gen(`k2') + qui:destring `kk', gen(`k2') jwdid_plot_calendar `k2' `mm1' `mm5' `mm6' , /// `style' `title' `name' `ytitle' `xtitle' `legend' `options' @@ -370,18 +370,18 @@ program jwdid_plot_group gettoken ll rest:rest gettoken uu rest:rest - qui:levelsof `t', local(tlev) + /*qui:levelsof `t', local(tlev) local tlb: value label `t' local xlab 0 " " foreach i of local tlev { local j = `j'+1 local xlab `xlab' `i' "`:label `tlb' `i''" - } + }*/ if `"`xtitle'"'=="" local xtitle xtitle("Groups") if `"`ytitle'"'=="" local ytitle ytitle("ATT") - local xlab `xlab' `=`j'+1' " " + *local xlab `xlab' `=`j'+1' " " jwdid_default , `options' `style' local gf11 `s(df11)' @@ -406,19 +406,19 @@ program jwdid_plot_calendar gettoken ll rest:rest gettoken uu rest:rest - qui:levelsof `t', local(tlev) + /*qui:levelsof `t', local(tlev) local tlb: value label `t' local xlab 0 " " foreach i of local tlev { local j = `j'+1 local xlab `xlab' `i' "`:label `tlb' `i''" - } + }*/ if `"`xtitle'"'=="" local xtitle xtitle("Periods") if `"`ytitle'"'=="" local ytitle ytitle("ATT") - local xlab `xlab' `=`j'+1' " " + *local xlab `xlab' `=`j'+1' " " jwdid_default , `options' `style' local gf11 `s(df11)' diff --git a/jwdid/unit_test.do b/jwdid/unit_test.do new file mode 100644 index 0000000..9e2721c --- /dev/null +++ b/jwdid/unit_test.do @@ -0,0 +1,60 @@ +** Unit test +clear +set seed 1 +set obs 2000 +gen ivar = _n +gen gvar = runiformint(3,6) +replace gvar = 0 if runiform()<.2 +gen x1 = runiform() +xtile dx=x1, n(2) +expand 10 +bysort ivar:gen tvar = _n +gen te = 1*(t>=(g-1) )*(g!=0) +gen y = (rnormal()) + te + +** installation +capture program drop _all +net install jwdid, from(C:\Users\Fernando\Documents\GitHub\stpackages\) replace +** Run +cd "C:\Users\Fernando\Documents\GitHub\stpackages\jwdid" + + +jwdid y , ivar(ivar) tvar(tvar) gvar(gvar) anti(3) +estat event, predict(xb) +estat plot +estat group, predict(xb) +estat plot +estat calendar, predict(xb) +estat plot +estat simple, over(dx) predict(xb) +estat plot + +jwdid y , tvar(tvar) gvar(gvar) +estat event, predict(xb) +estat plot +estat group, predict(xb) +estat plot +estat calendar, predict(xb) +estat plot +estat simple, over(dx) predict(xb) +estat plot + +jwdid y , ivar(ivar) tvar(tvar) gvar(gvar) never +estat event, predict(xb) +estat plot +estat group, predict(xb) +estat plot +estat calendar, predict(xb) +estat plot +estat simple, over(dx) predict(xb) +estat plot + +jwdid y x1, tvar(tvar) gvar(gvar) never cluster(ivar) +estat event, pretrend +estat plot +estat group +estat plot +estat calendar +estat plot +estat simple, over(dx) +estat plot \ No newline at end of file