Skip to content

Commit

Permalink
Merge pull request #177 from worldbank/develop
Browse files Browse the repository at this point in the history
Merging of version 6.1 to the master branch. Part of checklist in #174
  • Loading branch information
kbjarkefur authored Nov 10, 2018
2 parents 48d0fd4 + 1ab671f commit 04b9118
Show file tree
Hide file tree
Showing 24 changed files with 117 additions and 73 deletions.
21 changes: 14 additions & 7 deletions src/ado_files/iebaltab.ado
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
*! version 6.0 19OCT2018 DIME Analytics [email protected]
*! version 6.1 09112018 DIME Analytics [email protected]

capture program drop iebaltab
program iebaltab

syntax varlist(numeric) [if] [in], ///
syntax varlist(numeric) [if] [in] [aw fw pw iw], ///
///
/*Group variable*/ ///
GRPVar(varname) ///
Expand Down Expand Up @@ -33,7 +33,7 @@
COVMISS(string) ///
COVMISSReg(string) ///
MISSMINmean(numlist min=1 max=1 >0) ///
weight(string) ///
WEIGHTold(string) ///
///
/*F-test*/ ///
FTest ///
Expand Down Expand Up @@ -82,7 +82,14 @@ qui {
*Set minimum version for this command
version 11

*Remove observations excluded by if and in
* Backwards compatibility for weight option
if "`weightold'" != "" & "`exp'" == "" {
tokenize `weightold', parse(=)
local weight "`1'"
local exp = "= `3'"
}

*Remove observations excluded by if and in
marksample touse, novarlist
keep if `touse'

Expand Down Expand Up @@ -692,13 +699,13 @@ qui {
if `WEIGHT_USED' == 1 {

* Parsing weight options
gettoken weight_type weight_var : weight, parse("=")
local weight_type = "`weight'"

* Parsing keeps the separating character
local weight_var : subinstr local weight_var "=" ""
local weight_var = subinstr("`exp'","=","",.)

* Test is weight type specified is valie
local weight_options "fweights pweights aweights iweights fw freq weight pw aw iw"
local weight_options "fweights pweights aweights iweights fweight pweight aweight iweight fw freq weight pw aw iw"

if `:list weight_type in weight_options' == 0 {

Expand Down
2 changes: 1 addition & 1 deletion src/ado_files/ieboilsave.ado
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*! version 6.0 19OCT2018 DIME Analytics [email protected]
*! version 6.1 09112018 DIME Analytics [email protected]

capture program drop ieboilsave
program ieboilsave , rclass
Expand Down
2 changes: 1 addition & 1 deletion src/ado_files/ieboilstart.ado
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*! version 6.0 19OCT2018 DIME Analytics [email protected]
*! version 6.1 09112018 DIME Analytics [email protected]

capture program drop ieboilstart
program ieboilstart , rclass
Expand Down
2 changes: 1 addition & 1 deletion src/ado_files/iecompdup.ado
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*! version 6.0 19OCT2018 DIME Analytics [email protected]
*! version 6.1 09112018 DIME Analytics [email protected]

capture program drop iecompdup
program iecompdup , rclass
Expand Down
86 changes: 59 additions & 27 deletions src/ado_files/ieddtab.ado
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
*! version 6.0 19OCT2018 DIME Analytics [email protected]
*! version 6.1 09112018 DIME Analytics [email protected]

cap program drop ieddtab
program define ieddtab, rclass

syntax varlist(numeric) [if] [in], ///
syntax varlist(numeric) [if] [in] [aw fw iw pw], ///
///
Time(varname numeric) TREATment(varname numeric) ///
[ ///
Expand All @@ -13,6 +13,7 @@ cap program drop ieddtab
///
/* Output display */ ///
STARLevels(numlist descending min=3 max=3 >0 <1) ///
stardrop ///
ROWLabtype(string) ///
rowlabtext(string) ///
ERRortype(string) ///
Expand All @@ -29,6 +30,7 @@ cap program drop ieddtab
TEXLabel(string) ///
TEXNotewidth(numlist min=1 max=1) ///
texvspace(string) ///
nonumbers ///
]

*Set minimum version for this command
Expand Down Expand Up @@ -250,7 +252,7 @@ cap program drop ieddtab
gen `interactionvar' = `treatment' * `time'

*Run the regression to get the double difference
qui reg `var' `treatment' `time' `interactionvar' `covariates', `error_estm'
qui reg `var' `treatment' `time' `interactionvar' `covariates' [`weight'`exp'], `error_estm'
mat resTable = r(table)

**This is why this is done first. All other calculations
Expand All @@ -274,7 +276,7 @@ cap program drop ieddtab
*Get the number of stars using sub-command countStars
local ++colindex
local pvalue = el(resTable,4,3)
countStars `pvalue' `starlevels'
countStars `pvalue' `starlevels' `stardrop'
mat `var'[1,`colindex'] = `r(stars)'

*Get the N of second difference regression
Expand All @@ -297,7 +299,7 @@ cap program drop ieddtab
forvalues tmt01 = 0/1 {

*Regress time against the outcome var one tmt group at the time
qui reg `var' `time' `covariates' if `treatment' == `tmt01' & `regsample' == 1, `error_estm'
qui reg `var' `time' `covariates' if `treatment' == `tmt01' & `regsample' == 1 [`weight'`exp'], `error_estm'
mat resTable = r(table)

//Get the 1st diff
Expand All @@ -312,7 +314,7 @@ cap program drop ieddtab
*Get the number of stars using sub-command countStars
local ++colindex
local pvalue = el(resTable,4,1)
countStars `pvalue' `starlevels'
countStars `pvalue' `starlevels' `stardrop'
mat `var'[1,`colindex'] = `r(stars)'

*Get the N of first difference regression
Expand All @@ -338,7 +340,7 @@ cap program drop ieddtab
forvalues t01 = 0/1 {

*Summary stats on this group
qui mean `var' if `treatment' == `t01' & `time' == `tmt01' & `regsample' == 1, `error_estm_mean'
qui mean `var' if `treatment' == `t01' & `time' == `tmt01' & `regsample' == 1 [`weight'`exp'], `error_estm_mean'

mat resTable = r(table)

Expand Down Expand Up @@ -405,11 +407,13 @@ cap program drop ieddtab

local note_obs "The baseline means only include observations not omitted in the 1st and 2nd differences. The number of observations in the 1st and 2nd differences includes both baseline and follow-up observations."

*Show stars levels
local star1_value : word 1 of `starlevels'
local star2_value : word 2 of `starlevels'
local star3_value : word 3 of `starlevels'
local note_stars "***, **, and * indicate significance at the `star3_value', `star2_value', and `star1_value' percent critical level."
*Only include note on stars levels if stardrop was NOT used
if "`stardrop'" == "" {
local star1_value : word 1 of `starlevels'
local star2_value : word 2 of `starlevels'
local star3_value : word 3 of `starlevels'
local note_stars "***, **, and * indicate significance at the `star3_value', `star2_value', and `star1_value' percent critical level."
}

*Only include note on covariates if covariates were used
if "`covariates'" != "" {
Expand All @@ -433,7 +437,21 @@ cap program drop ieddtab
if "`vce_type'" == "bootstrap" local note_error "All columns display `variance_type_name' estimated using bootstrap. "
}

local note `"`note_obs' `note_stars' `note_cov' `note_error'"'
* Add note on weights
if "`weight'" != "" {
local weightvar = subinstr("`exp'", "=", "", .)
local weightvar = stritrim(strtrim(`"`weightvar'"'))

noi di "`weight'"
if "`weight'" == "aweight" local weightopt analytical
else if "`weight'" == "fweight" local weightopt frequency
else if "`weight'" == "pweight" local weightopt probability
else if "`weight'" == "iweight" local weightopt importance

local note_weight "Variable `weightvar' used as `weightopt' weight. "
}

local note `"`note_obs' `note_stars' `note_cov' `note_error' `note_weight'"'

}

Expand All @@ -454,7 +472,7 @@ cap program drop ieddtab
*************/

outputwindow `varlist' , ddtab_resultMap(ddtab_resultMap) labmaxlen(`labmaxlen') rwlbls(`rowlabels') ///
starlevels("`starlevels'") covariates(`covariates') `errortype' format(`format') note(`note') `cluster'
`errortype' format(`format') note(`note') `cluster'

/*************
Expand All @@ -466,8 +484,8 @@ cap program drop ieddtab
outputtex `varlist', ddtab_resultMap(ddtab_resultMap) ///
savetex(`savetex') `replace' ///
`texdocument' texcaption("`texcaption'") texlabel("`texlabel'") texnotewidth(`texnotewidth') ///
`onerow' starlevels("`starlevels'") format(`format') rwlbls("`rowlabels'") errortype(`errortype') ///
note(`note') texvspace("`texvspace'") `cluster'
`onerow' format(`format') rwlbls("`rowlabels'") errortype(`errortype') ///
note(`note') texvspace("`texvspace'") `cluster' `numbers'

}

Expand Down Expand Up @@ -673,12 +691,16 @@ end
cap program drop countStars
program define countStars, rclass

args pvalue star1 star2 star3
args pvalue star1 star2 star3 stardrop

local stars 0
foreach star_p_level in `star1' `star2' `star3' {

if `pvalue' < `star_p_level' local ++stars
*Option to suppress all stars
if "`stardrop'" == "" {
foreach star_p_level in `star1' `star2' `star3' {

if `pvalue' < `star_p_level' local ++stars
}
}

return local stars `stars'
Expand Down Expand Up @@ -833,8 +855,8 @@ end
cap program drop outputwindow
program define outputwindow

syntax varlist , ddtab_resultMap(name) labmaxlen(numlist) rwlbls(string) starlevels(string) format(string) ///
[covariates(string) errhide sd se note(string) cluster]
syntax varlist , ddtab_resultMap(name) labmaxlen(numlist) rwlbls(string) format(string) ///
[errhide sd se note(string) cluster]

*Prepare lables for the erorrs to be displayed (in case any)
if "`sd'" != "" local errlabel "SD"
Expand Down Expand Up @@ -977,8 +999,6 @@ end

*************************
* Write notes below the table

*List covariates used
if (`"`note'"' != "") {
noi di as text `"{pstd}`note'{p_end}"'
}
Expand Down Expand Up @@ -1088,7 +1108,7 @@ cap program drop outputtex

syntax varlist, ddtab_resultMap(name) savetex(string) note(string) ///
[replace onerow starlevels(string) format(string) rwlbls(string) errortype(string) ///
texdocument texcaption(string) texlabel(string) texnotewidth(numlist) texvspace(string) cluster]
texdocument texcaption(string) texlabel(string) texnotewidth(numlist) texvspace(string) cluster nonumbers]

* Replace tex file?
if "`replace'" != "" local texreplace replace
Expand All @@ -1110,7 +1130,7 @@ cap program drop outputtex
texpreamble , texname("`texname'") texfile("`texfile'") texcaption("`texcaption'") texlabel("`texlabel'") `texdocument'

* Write table header
texheader , texname("`texname'") texfile("`texfile'") `onerow' errortype(`errortype') `cluster'
texheader , texname("`texname'") texfile("`texfile'") `onerow' errortype(`errortype') `cluster' `numbers'

* Write results
texresults `varlist', ddtab_resultMap(ddtab_resultMap) ///
Expand Down Expand Up @@ -1406,7 +1426,7 @@ end
cap program drop texheader
program define texheader

syntax , texname(string) texfile(string) errortype(string) [onerow cluster]
syntax , texname(string) texfile(string) errortype(string) [onerow cluster nonumbers]

** Calculate number of rows

Expand All @@ -1429,6 +1449,17 @@ cap program drop texheader
}
}

*Unless option nonumbers is used, number all columns in tex output
local colnorow = ""
if "`numbers'" != "nonumbers" {
local colnomax = strlen("`colstring'") - 1
forvalues colno = 1/`colnomax' {
local colnorow = `"`colnorow' & (`colno')"'
}
local colnorow = `"`colnorow' \\"'
}

*Write part of header that explains which type of errors are displayed
if "`errortype'" == "errhide" {
if "`onerow'" != "" {
local errortitle ""
Expand All @@ -1451,7 +1482,8 @@ cap program drop texheader
"\hline \hline \\[-1.8ex]" _n ///
"& \multicolumn{`toprowcols'}{c}{Control} & \multicolumn{`toprowcols'}{c}{Treatment} & \multicolumn{`bottomrowcols'}{c}{Difference-in-differences} \\" _n ///
"& \multicolumn{`bottomrowcols'}{c}{Baseline} & \multicolumn{`bottomrowcols'}{c}{Difference} & \multicolumn{`bottomrowcols'}{c}{Baseline} & \multicolumn{`bottomrowcols'}{c}{Difference} & \multicolumn{`bottomrowcols'}{c}{} \\" _n ///
"Variable `ncol' & Mean`errortitle' `ncol' & Coef`errortitle' `ncol' & Mean`errortitle' `ncol' & Coef`errortitle' `ncol' & Coef`errortitle' \\ \hline" _n
"Variable `ncol' & Mean`errortitle' `ncol' & Coef`errortitle' `ncol' & Mean`errortitle' `ncol' & Coef`errortitle' `ncol' & Coef`errortitle' \\" _n ///
"`colnorow' \hline" _n
file close `texname'

end
Expand Down
2 changes: 1 addition & 1 deletion src/ado_files/iedropone.ado
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*! version 6.0 19OCT2018 DIME Analytics [email protected]
*! version 6.1 09112018 DIME Analytics [email protected]

capture program drop iedropone
program define iedropone ,
Expand Down
8 changes: 5 additions & 3 deletions src/ado_files/ieduplicates.ado
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*! version 6.0 19OCT2018 DIME Analytics [email protected]
*! version 6.1 09112018 DIME Analytics [email protected]

capture program drop ieduplicates
program ieduplicates , rclass
Expand Down Expand Up @@ -167,7 +167,7 @@
*Test that the ID variable is in the imported report
if `:list idvar in existingExcelVars' == 0 {

noi display as error "{phang}The ID variable `idvar' does not exist in the previously exported Excle file. If you renamed the ID variable you need to rename it manually in the Excel report or start a new Excel report by renaming or moving the original report, then run the command again and create a new file and manually copy any corrections from the old file to the new. If you changed the ID varaible you need to start with a new report.{p_end}"
noi display as error "{phang}The ID variable `idvar' does not exist in the previously exported Excle file. If you renamed the ID variable you need to rename it manually in the Excel report or start a new Excel report by renaming or moving the original report, then run the command again and create a new file and manually copy any corrections from the old file to the new. If you changed the ID variable you need to start with a new report.{p_end}"
noi di ""
error 111
exit
Expand Down Expand Up @@ -333,6 +333,8 @@
}

*Same error for any incorrect input

di as error "{phang}Since there was at least one error in the Excel report no corrections have been made to the duplicates in the data set. Please address the errors above and then run the command again.{p_end}"
error 198
exit
}
Expand Down Expand Up @@ -613,7 +615,7 @@
levelsof newID if missing(real(newID)), local(NaN_values) clean

* Output error message
di as error "{phang}The ID varaible `idvar' is numeric but newID has thes non-numeric values: `NaN_values'. Update newID to only contain numeric values or see option tostringok.{p_end}"
di as error "{phang}The ID variable `idvar' is numeric but newID has these non-numeric values: `NaN_values'. Update newID to only contain numeric values or see option tostringok.{p_end}"
error 109
exit
}
Expand Down
2 changes: 1 addition & 1 deletion src/ado_files/iefolder.ado
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*! version 6.0 19OCT2018 DIME Analytics [email protected]
*! version 6.1 09112018 DIME Analytics [email protected]

cap program drop iefolder
program define iefolder
Expand Down
2 changes: 1 addition & 1 deletion src/ado_files/iegitaddmd.ado
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*! version 6.0 19OCT2018 DIME Analytics [email protected]
*! version 6.1 09112018 DIME Analytics [email protected]

cap program drop iegitaddmd
program define iegitaddmd
Expand Down
4 changes: 2 additions & 2 deletions src/ado_files/iegraph.ado
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*! version 6.0 19OCT2018 DIME Analytics [email protected]
*! version 6.1 09112018 DIME Analytics [email protected]

cap program drop iegraph
program define iegraph, rclass
Expand All @@ -21,7 +21,7 @@ cap program drop iegraph
ignoredummytest ///
norestore ///
save(string) *]

if "`restore'" == "" preserve

qui {
Expand Down
2 changes: 1 addition & 1 deletion src/ado_files/iematch.ado
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*! version 6.0 19OCT2018 DIME Analytics [email protected]
*! version 6.1 09112018 DIME Analytics [email protected]

cap program drop iematch
program define iematch
Expand Down
6 changes: 3 additions & 3 deletions src/ado_files/ietoolkit.ado
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
*! version 6.0 19OCT2018 DIME Analytics [email protected]
*! version 6.1 09112018 DIME Analytics [email protected]

capture program drop ietoolkit
program ietoolkit, rclass

* UPDATE THESE LOCALS FOR EACH NEW VERSION PUBLISHED
local version "6.0"
local versionDate "19OCT2018"
local version "6.1"
local versionDate "11NOV2018"


syntax [anything]
Expand Down
Loading

0 comments on commit 04b9118

Please sign in to comment.