| |
| |
| |
| |
|
|
| |
|
|
| capture program drop iebaltab_edit |
| program iebaltab_edit |
|
|
| syntax varlist(numeric) [if] [in] [aw fw pw iw], |
| |
| |
| GRPVar(varname) |
| |
| [ |
| |
| ORder(numlist int min=1) |
| COntrol(numlist int max=1) |
| TOTal |
| |
| |
| GRPCodes |
| GRPLabels(string) |
| TOTALLabel(string) |
| ROWVarlabels |
| ROWLabels(string) |
| onerow |
| onenrow |
| |
| |
| FIXedeffect(varname) |
| COVariates(varlist ts fv) |
| COVARMISSOK |
| vce(string) |
| BALMISS(string) |
| BALMISSReg(string) |
| COVMISS(string) |
| COVMISSReg(string) |
| MISSMINmean(numlist min=1 max=1 >0) |
| WEIGHTold(string) |
| |
| |
| FTest |
| FMissok |
| FNOOBS |
| |
| |
| NOTtest |
| NORMDiff |
| PTtest |
| PFtest |
| FEQTest |
| PBoth |
| STDev |
| STARlevels(numlist descending min=3 max=3 >0 <1) |
| STARSNOadd |
| FORMat(string) |
| TBLNote(string) |
| NOTECombine |
| TBLNONote |
| |
| |
| SAVE(string) |
| SAVETex(string) |
| TEXNotewidth(numlist min=1 max=1) |
| TEXCaption(string) |
| TEXLabel(string) |
| TEXDOCument |
| texvspace(string) |
| texcolwidth(string) |
| BROWSE |
| SAVEBRowse |
| REPLACE |
| ] |
|
|
|
|
| |
| |
|
|
| |
| |
|
|
| preserve |
| qui { |
|
|
| |
| version 11 |
|
|
| |
| if "`weightold'" != "" & "`exp'" == "" { |
| tokenize `weightold', parse(=) |
| local weight "`1'" |
| local exp = "= `3'" |
| } |
|
|
| |
| marksample touse, novarlist |
| keep if `touse' |
|
|
| if 1 { |
|
|
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| local balancevars `varlist' |
|
|
|
|
| |
|
|
| |
| if "`control'" == "" local CONTROL_USED = 0 |
| if "`control'" != "" local CONTROL_USED = 1 |
|
|
| |
| if "`order'" == "" local ORDER_USED = 0 |
| if "`order'" != "" local ORDER_USED = 1 |
|
|
| |
| if "`grpcodes'" == "" local NOGRPLABEL_USED = 0 |
| if "`grpcodes'" != "" local NOGRPLABEL_USED = 1 |
|
|
| |
| if "`grplabels'" == "" local GRPLABEL_USED = 0 |
| if "`grplabels'" != "" local GRPLABEL_USED = 1 |
|
|
| |
| if "`total'" == "" local TOTAL_USED = 0 |
| if "`total'" != "" local TOTAL_USED = 1 |
|
|
| |
| if "`totallabel'" == "" local TOTALLABEL_USED = 0 |
| if "`totallabel'" != "" local TOTALLABEL_USED = 1 |
|
|
|
|
| |
|
|
| |
| if "`rowvarlabels'" == "" local ROWVARLABEL_USED = 0 |
| if "`rowvarlabels'" != "" local ROWVARLABEL_USED = 1 |
|
|
| |
| if "`rowlabels'" == "" local ROWLABEL_USED = 0 |
| if "`rowlabels'" != "" local ROWLABEL_USED = 1 |
|
|
| |
| if "`onenrow'" != "" local onerow = "onerow" |
| if "`onerow'" == "" local ONEROW_USED = 0 |
| if "`onerow'" != "" local ONEROW_USED = 1 |
|
|
|
|
|
|
|
|
| |
|
|
| |
| if "`ftest'" == "" local FTEST_USED = 0 |
| if "`ftest'" != "" local FTEST_USED = 1 |
|
|
| |
| if "`fmissok'" == "" local F_MISS_OK = 0 |
| if "`fmissok'" != "" local F_MISS_OK = 1 |
|
|
| |
| if "`fnoobs'" == "" local F_NO_OBS = 0 |
| if "`fnoobs'" != "" local F_NO_OBS = 1 |
|
|
| |
| if "`fixedeffect'" == "" local FIX_EFFECT_USED = 0 |
| if "`fixedeffect'" != "" local FIX_EFFECT_USED = 1 |
|
|
| |
| if "`covariates'" == "" local COVARIATES_USED = 0 |
| if "`covariates'" != "" local COVARIATES_USED = 1 |
|
|
| |
| if "`covarmissok'" == "" local COVARMISSOK_USED = 0 |
| if "`covarmissok'" != "" local COVARMISSOK_USED = 1 |
|
|
| |
| if "`vce'" == "" local VCE_USED = 0 |
| if "`vce'" != "" local VCE_USED = 1 |
|
|
| |
| if "`balmiss'" == "" local BALMISS_USED = 0 |
| if "`balmiss'" != "" local BALMISS_USED = 1 |
|
|
| |
| if "`balmissreg'" == "" local BALMISSREG_USED = 0 |
| if "`balmissreg'" != "" local BALMISSREG_USED = 1 |
|
|
| |
| if "`covmiss'" == "" local COVMISS_USED = 0 |
| if "`covmiss'" != "" local COVMISS_USED = 1 |
|
|
| |
| if "`covmissreg'" == "" local COVMISSREG_USED = 0 |
| if "`covmissreg'" != "" local COVMISSREG_USED = 1 |
|
|
| |
| if "`missminmean'" == "" local MISSMINMEAN_USED = 0 |
| if "`missminmean'" != "" local MISSMINMEAN_USED = 1 |
|
|
| |
| if "`starlevels'" == "" local STARLEVEL_USED = 0 |
| if "`starlevels'" != "" local STARLEVEL_USED = 1 |
|
|
| |
| if "`starsnoadd'" == "" local STARSNOADD_USED = 0 |
| if "`starsnoadd'" != "" local STARSNOADD_USED = 1 |
|
|
| |
| if "`nottest'" == "" local TTEST_USED = 1 |
| if "`nottest'" != "" local TTEST_USED = 0 |
|
|
| |
| if "`pttest'" == "" local PTTEST_USED = 0 |
| if "`pttest'" != "" local PTTEST_USED = 1 |
|
|
| |
| if "`pftest'" == "" local PFTEST_USED = 0 |
| if "`pftest'" != "" local PFTEST_USED = 1 |
|
|
| |
| if "`pboth'" == "" local PBOTH_USED = 0 |
| if "`pboth'" != "" local PBOTH_USED = 1 |
| if `PBOTH_USED' == 1 local PTTEST_USED = 1 |
| if `PBOTH_USED' == 1 local PFTEST_USED = 1 |
|
|
| |
| if "`stdev'" == "" local STDEV_USED = 0 |
| if "`stdev'" != "" local STDEV_USED = 1 |
|
|
| |
| if "`weight'" == "" local WEIGHT_USED = 0 |
| if "`weight'" != "" local WEIGHT_USED = 1 |
|
|
| |
| if "`feqtest'" == "" local FEQTEST_USED = 0 |
| if "`feqtest'" != "" local FEQTEST_USED = 1 |
|
|
| |
| if "`normdiff'" == "" local NORMDIFF_USED = 0 |
| if "`normdiff'" != "" local NORMDIFF_USED = 1 |
|
|
|
|
| |
|
|
| |
| if "`format'" == "" local FORMAT_USED = 0 |
| if "`format'" != "" local FORMAT_USED = 1 |
|
|
| |
| if "`save'" == "" local SAVE_USED = 0 |
| if "`save'" != "" local SAVE_USED = 1 |
|
|
| |
| if "`savetex'" == "" local SAVE_TEX_USED = 0 |
| if "`savetex'" != "" local SAVE_TEX_USED = 1 |
|
|
| |
| if "`texnotewidth'" == "" local NOTEWIDTH_USED = 0 |
| if "`texnotewidth'" != "" local NOTEWIDTH_USED = 1 |
|
|
| |
| if "`texcaption'" == "" local CAPTION_USED = 0 |
| if "`texcaption'" != "" local CAPTION_USED = 1 |
|
|
| |
| if "`texlabel'" == "" local LABEL_USED = 0 |
| if "`texlabel'" != "" local LABEL_USED = 1 |
|
|
| |
| if "`texdocument'" == "" local TEXDOC_USED = 0 |
| if "`texdocument'" != "" local TEXDOC_USED = 1 |
|
|
| |
| if "`texvspace'" == "" local TEXVSPACE_USED = 0 |
| if "`texvspace'" != "" local TEXVSPACE_USED = 1 |
|
|
| |
| if "`texcolwidth'" == "" local TEXCOLWIDTH_USED = 0 |
| if "`texcolwidth'" != "" local TEXCOLWIDTH_USED = 1 |
|
|
| |
| if "`browse'" == "" local BROWSE_USED = 0 |
| if "`browse'" != "" local BROWSE_USED = 1 |
|
|
| |
| if "`savebrowse'" == "" local SAVE_BROWSE_USED = 0 |
| if "`savebrowse'" != "" local SAVE_BROWSE_USED = 1 |
|
|
| |
| if "`replace'" == "" local REPLACE_USED = 0 |
| if "`replace'" != "" local REPLACE_USED = 1 |
|
|
| |
| if "`tblnote'" == "" local NOTE_USED = 0 |
| if "`tblnote'" != "" local NOTE_USED = 1 |
|
|
| |
| if "`notecombine'" == "" local NOTECOMBINE_USED = 0 |
| if "`notecombine'" != "" local NOTECOMBINE_USED = 1 |
|
|
| |
| if "`tblnonote'" == "" local NONOTE_USED = 0 |
| if "`tblnonote'" != "" local NONOTE_USED = 1 |
|
|
|
|
| |
| |
| |
| |
| |
| |
| |
|
|
| cap confirm numeric variable `grpvar' |
|
|
| if _rc != 0 { |
|
|
| |
|
|
| if `CONTROL_USED' == 1 { |
| di as error "{pstd}The option control() can only be used if variable {it:`grpvar'} is a numeric variable. Use {help encode} to generate a numeric version of variable {it:`grpvar'}. It is best practice to store all categorical variables as labeled numeric variables.{p_end}" |
| error 198 |
| } |
| if `ORDER_USED' == 1 { |
| di as error "{pstd}The option order() can only be used if variable {it:`grpvar'} is a numeric variable. Use {help encode} to generate a numeric version of variable {it:`grpvar'}. It is best practice to store all categorical variables as labeled numeric variables.{p_end}" |
| error 198 |
| } |
| if `NOGRPLABEL_USED' == 1 { |
| di as error "{pstd}The option grpcodes can only be used if variable {it:`grpvar'} is a numeric variable. Use {help encode} to generate a numeric version of variable {it:`grpvar'}. It is best practice to store all categorical variables as labeled numeric variables.{p_end}" |
| error 198 |
| } |
| if `GRPLABEL_USED' == 1 { |
| di as error "{pstd}The option grplabels() can only be used if variable {it:`grpvar'} is a numeric variable. Use {help encode} to generate a numeric version of variable {it:`grpvar'}. It is best practice to store all categorical variables as labeled numeric variables.{p_end}" |
| error 198 |
| } |
|
|
| |
| tempvar grpvar_code |
| encode `grpvar' , gen(`grpvar_code') |
|
|
| |
| local grpvar `grpvar_code' |
|
|
| } |
|
|
|
|
| |
| drop if `grpvar' >= . |
|
|
| |
| levelsof `grpvar', local(GRP_CODE_LEVELS) |
|
|
| |
| local GRPVAR_VALUE_LABEL : value label `grpvar' |
|
|
| |
| local GRPVAR_NUM_GROUPS : word count `GRP_CODE_LEVELS' |
|
|
| |
| if "`GRPVAR_VALUE_LABEL'" == "" local GRPVAR_HAS_VALUE_LABEL = 0 |
| if "`GRPVAR_VALUE_LABEL'" != "" local GRPVAR_HAS_VALUE_LABEL = 1 |
|
|
| |
| local NUM_COL_GRP_TOT = `GRPVAR_NUM_GROUPS' + `TOTAL_USED' |
|
|
|
|
| |
| |
|
|
| |
|
|
| |
| |
|
|
| |
|
|
| cap confirm numeric variable `grpvar' |
| if _rc != 0 { |
| noi display as error "{phang}The variable listed in grpvar(`grpvar') is not a numeric variable. See {help encode} for options on how to make a categorical string variable into a categorical numeric variable{p_end}" |
| error 108 |
| } |
| else { |
| |
| |
| |
| cap assert ( int(`grpvar') == `grpvar' ) |
| if _rc == 9 { |
| noi display as error "{phang}The variable in grpvar(`grpvar') is not a categorical variable. The variable may only include integers where each integer indicates which group each observation belongs to. See tabulation of `grpvar' below:{p_end}" |
| noi tab `grpvar', nol |
| error 109 |
| } |
| } |
|
|
|
|
| |
|
|
| |
| |
|
|
| local control_correct : list control in GRP_CODE_LEVELS |
| if `control_correct' == 0 { |
| noi display as error "{phang}The code listed in control(`control') is not used in grpvar(`grpvar'). See tabulation of `grpvar' below:" |
| noi tab `grpvar', nol |
| error 197 |
| } |
|
|
| local order_correct : list order in GRP_CODE_LEVELS |
| if `order_correct' == 0 { |
| noi display as error "{phang}One or more codes listed in order(`order') are not used in grpvar(`grpvar'). See tabulation of `grpvar' below:" |
| noi tab `grpvar', nol |
| error 197 |
| } |
|
|
| if `GRPLABEL_USED' == 1 { |
|
|
| local col_labels_to_tokenize `grplabels' |
|
|
| while "`col_labels_to_tokenize'" != "" { |
|
|
| |
| gettoken codeAndLabel col_labels_to_tokenize : col_labels_to_tokenize, parse("@") |
|
|
| |
| gettoken code label : codeAndLabel |
|
|
|
|
| |
|
|
| |
| local code_correct : list code in GRP_CODE_LEVELS |
| if `code_correct' == 0 { |
| noi display as error "{phang}Code [`code'] listed in grplabels(`grplabels') is not used in grpvar(`grpvar'). See tabulation of `grpvar' below:" |
| noi tab `grpvar', nol |
| error 198 |
| } |
|
|
| |
| local grpLabelCodes `"`grpLabelCodes' "`code'" "' |
|
|
|
|
| |
|
|
| |
| local label = trim("`label'") |
|
|
| |
| if "`label'" == "" { |
| noi display as error "{phang}For code [`code'] listed in grplabels(`grplabels') you have not specified any label. Labels are requried for all codes listed in grplabels(). See tabulation of `grpvar' below:" |
| noi tab `grpvar', nol |
| error 198 |
| } |
|
|
| |
| local grpLabelLables `"`grpLabelLables' "`label'" "' |
|
|
|
|
| |
| local col_labels_to_tokenize = subinstr("`col_labels_to_tokenize'" ,"@","",1) |
| } |
| } |
|
|
| if `ROWLABEL_USED' { |
|
|
| |
|
|
| |
| local row_labels_to_tokenize `rowlabels' |
|
|
| while "`row_labels_to_tokenize'" != "" { |
|
|
| |
| gettoken nameAndLabel row_labels_to_tokenize : row_labels_to_tokenize, parse("@") |
|
|
| |
| gettoken name label : nameAndLabel |
|
|
| |
|
|
| |
| local name_correct : list name in balancevars |
| if `name_correct' == 0 { |
| noi display as error "{phang}Variable [`name'] listed in rowlabels(`rowlabels') is not found among the variables included in the balance table." |
| error 111 |
| } |
|
|
| |
| local rowLabelNames `"`rowLabelNames' "`name'" "' |
|
|
|
|
| |
|
|
| |
| local label = trim("`label'") |
|
|
| |
| if "`label'" == "" { |
| noi display as error "{phang}For variable [`name'] listed in rowlabels(`rowlabels') you have not specified any label. Labels are requried for all variables listed in rowlabels(). The variable name itself will be used for any variables omitted from rowlabels(). See also option {help iebaltab:rowvarlabels}" |
| noi tab `grpvar', nol |
| error 198 |
| } |
|
|
| |
| local rowLabelLabels `"`rowLabelLabels' "`label'" "' |
|
|
| |
| local row_labels_to_tokenize = subinstr("`row_labels_to_tokenize'" ,"@","",1) |
| } |
| } |
|
|
| if `TOTALLABEL_USED' & !`TOTAL_USED' { |
|
|
| |
| noi display as error "{phang}Option totallabel() may only be used together with the option total" |
| error 197 |
| } |
|
|
|
|
| |
| local SHOW_NCLUSTER 0 |
|
|
| if `VCE_USED' == 1 { |
|
|
| local vce_nocomma = subinstr("`vce'", "," , " ", 1) |
|
|
| tokenize "`vce_nocomma'" |
| local vce_type `1' |
|
|
| if "`vce_type'" == "robust" { |
|
|
| |
| } |
| else if "`vce_type'" == "cluster" { |
|
|
| |
| local SHOW_NCLUSTER 1 |
|
|
| local cluster_var `2' |
|
|
| cap confirm variable `cluster_var' |
|
|
| if _rc { |
|
|
| |
| noi display as error "{phang}The cluster variable in vce(`vce') does not exist or is invalid for any other reason. See {help vce_option :help vce_option} for more information. " |
| error _rc |
|
|
| } |
| } |
| else if "`vce_type'" == "bootstrap" { |
|
|
| |
| } |
| else { |
|
|
| |
| noi display as error "{phang}The vce type `vce_type' in vce(`vce') is not allowed. Only robust, cluster and bootstrap are allowed. See {help vce_option :help vce_option} for more information." |
| error 198 |
|
|
| } |
| } |
|
|
| if `STARSNOADD_USED' == 0 { |
|
|
| |
| if `STARLEVEL_USED' == 1 { |
|
|
| |
| tokenize "`starlevels'" |
|
|
| |
| local p1star `1' |
| local p2star `2' |
| local p3star `3' |
| } |
| else { |
| |
| local p1star .1 |
| local p2star .05 |
| local p3star .01 |
| } |
|
|
| |
| |
| local p1star_percent = `p1star' * 100 |
| local p2star_percent = `p2star' * 100 |
| local p3star_percent = `p3star' * 100 |
| } |
| else { |
|
|
| |
| |
| local p1star |
| local p2star |
| local p3star |
| } |
|
|
| |
| if `STARSNOADD_USED' & `STARLEVEL_USED' { |
| |
| noi display as error "{phang}Option starlevels() may not be used in combination with option starsnoadd" |
| error 197 |
| } |
|
|
|
|
|
|
| |
| if `BALMISS_USED' & `BALMISSREG_USED' { |
| |
| noi display as error "{phang}Option balmiss() may not be used in combination with option balmissreg()" |
| error 197 |
| } |
|
|
| if `COVMISS_USED' & `COVMISSREG_USED' { |
| |
| noi display as error "{phang}Option covmiss() may not be used in combination with option covmissreg()" |
| error 197 |
| } |
|
|
| if !`TTEST_USED' { |
| if `PTTEST_USED' { |
| |
| noi display as error "{phang}Option pttest may not be used in combination with option nottest" |
| error 197 |
| } |
| if `PBOTH_USED' { |
| |
| noi display as error "{phang}Option pboth may not be used in combination with option nottest" |
| error 197 |
| } |
| } |
|
|
| if `FTEST_USED' & !`TTEST_USED' & !`NORMDIFF_USED' { |
| |
| |
| noi di as error "{phang}Option ftest may not only be used if either t-tests or normalized differences are used. F-test for joing significance of balance variables will not be displayed. In order to display it, either use option normdiff or remove option nottest.{p_end}" |
| local FTEST_USED = 0 |
|
|
| } |
|
|
| |
| if `BALMISS_USED' == 1 iereplacestringtest "balmiss" "`balmiss'" |
| if `BALMISSREG_USED' == 1 iereplacestringtest "balmissreg" "`balmissreg'" |
| if `COVMISS_USED' == 1 iereplacestringtest "covmiss" "`covmiss'" |
| if `COVMISSREG_USED' == 1 iereplacestringtest "covmissreg" "`covmissreg'" |
|
|
|
|
| if `FIX_EFFECT_USED' == 1 { |
|
|
| cap assert `fixedeffect' < . |
| if _rc == 9 { |
|
|
| noi display as error "{phang}The variable in fixedeffect(`fixedeffect') is missing for some observations. This would cause observations to be dropped in the estimation regressions. See tabulation of `fixedeffect' below:{p_end}" |
| noi tab `fixedeffect', m |
| error 109 |
| } |
|
|
| } |
|
|
| |
| if `COVARIATES_USED' == 1 { |
|
|
| foreach covar of local covariates { |
|
|
| |
| local replaceoptions |
|
|
| |
| if `COVMISS_USED' local replaceoptions `" `replaceoptions' replacetype("`covmiss'") "' |
| if `COVMISSREG_USED' local replaceoptions `" `replaceoptions' replacetype("`covmissreg'") regonly "' |
|
|
| |
| if "`covmiss'" == "groupmean" local replaceoptions `" `replaceoptions' groupvar(`grpvar') groupcodes("`GRP_CODE_LEVELS'") "' |
| if "`covmissreg'" == "groupmean" local replaceoptions `" `replaceoptions' groupvar(`grpvar') groupcodes("`GRP_CODE_LEVELS'") "' |
|
|
| |
| if `MISSMINMEAN_USED' == 1 local replaceoptions `" `replaceoptions' minobsmean(`missminmean') "' |
| if `MISSMINMEAN_USED' == 0 local replaceoptions `" `replaceoptions' minobsmean(10) "' |
|
|
| |
| if (`COVMISS_USED' | `COVMISSREG_USED') iereplacemiss `covariates', `replaceoptions' |
|
|
| if `COVARMISSOK_USED' != 1 { |
|
|
| cap assert `covar' < . |
| if _rc == 9 { |
|
|
| noi display as error "{phang}The variable `covar' specified in covariates() has missing values for one or more observations. This would cause observations to be dropped in the estimation regressions. To allow for observations to be dropped see option covarmissok and to make the command treat missing values as zero see option covmiss() and covmissreg(). Click {stata tab `covar' `if' `in', m} to see the missing values.{p_end}" |
| error 109 |
| } |
| } |
| } |
| } |
|
|
| if `WEIGHT_USED' == 1 { |
|
|
| |
| local weight_type = "`weight'" |
|
|
| |
| local weight_var = subinstr("`exp'","=","",.) |
|
|
| |
| 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 { |
|
|
| noi display as error "{phang} The option `weight_type' specified in weight() is not a valid weight option. Weight options are: fweights, fw, freq, weight, pweights, pw, aweights, aw, iweights, and iw. {p_end}" |
| error 198 |
|
|
| } |
|
|
| |
| capture confirm variable `weight_var' |
|
|
| if _rc { |
|
|
| noi display as error "{phang} The option `weight_var' specified in weight() is not a variable. {p_end}" |
| error 198 |
| } |
| } |
|
|
|
|
|
|
| |
|
|
| |
| if `FORMAT_USED' == 1 { |
|
|
| |
| |
| |
| |
| tempvar formattest |
| gen `formattest' = 1 |
| cap format `formattest' `format' |
|
|
| if _rc == 120 { |
|
|
| di as error "{phang}The format specified in format(`format') is not a valid Stata format. See {help format} for a list of valid Stata formats. This command only accept the f, fc, g, gc and e format.{p_end}" |
| error 120 |
| } |
| else if _rc != 0 { |
|
|
| di as error "{phang}Something unexpected happened related to the option format(`format'). Make sure that the format you specified is a valid format. See {help format} for a list of valid Stata formats. If this problem remains, please report this error to kbjarkefur@worldbank.org.{p_end}" |
| error _rc |
| } |
| else { |
| |
|
|
| local fomrmatAllowed 0 |
| local charLast = substr("`format'", -1,.) |
| local char2Last = substr("`format'", -2,.) |
|
|
| if "`charLast'" == "f" | "`charLast'" == "e" { |
| local fomrmatAllowed 1 |
| } |
| else if "`charLast'" == "g" { |
| if "`char2Last'" == "tg" { |
| |
| local fomrmatAllowed 0 |
| } |
| else { |
|
|
| |
| local fomrmatAllowed 1 |
| } |
| } |
| else if "`charLast'" == "c" { |
| if "`char2Last'" != "gc" & "`char2Last'" != "fc" { |
| |
| local fomrmatAllowed 0 |
| } |
| else { |
|
|
| |
| local fomrmatAllowed 1 |
| } |
| } |
| else { |
| |
| local fomrmatAllowed 0 |
| } |
| if `fomrmatAllowed' == 0 { |
| di as error "{phang}The format specified in format(`format') is not allowed. Only format f, fc, g, gc and e are allowed. See {help format} for details on Stata formats.{p_end}" |
| error 120 |
| } |
| |
| local diformat = "`format'" |
| } |
| } |
| else { |
| |
| local diformat = "%9.3f" |
| } |
|
|
|
|
| |
| if `NOTECOMBINE_USED' & `NONOTE_USED' { |
|
|
| |
| noi display as error "{phang}Option tblnonote may not be used in combination with option notecombine" |
| error 197 |
| } |
|
|
| if `SAVE_USED' | `SAVE_TEX_USED' { |
| if `SAVE_USED' { |
|
|
| |
| |
| |
|
|
| |
| local file_suffix = "`save'" |
|
|
| |
| local dot_index = strpos("`file_suffix'",".") |
|
|
| |
| if `dot_index' == 0 local file_suffix "" |
|
|
| |
| |
| while `dot_index' > 0 { |
|
|
| |
| local file_suffix = substr("`file_suffix'", `dot_index' + 1, .) |
|
|
| |
| local dot_index = strpos("`file_suffix'",".") |
| } |
|
|
| |
| if "`file_suffix'" == "" { |
|
|
| local save `"`save'.xlsx"' |
| } |
|
|
| |
| else if !("`file_suffix'" == "xls" | "`file_suffix'" == "xlsx") { |
|
|
| noi display as error "{phang}The file format specified in save(`save') is other than .xls or .xlsx. Only those two formats are allowed. If no format is specified .xlsx is the default. If you have a . in your file path, for example in a folder name, then you must specify the file extension .xls or .xlsx.{p_end}" |
| error 198 |
| } |
| } |
| if `SAVE_TEX_USED' { |
|
|
| |
| |
| |
|
|
| |
| local tex_file_suffix = "`savetex'" |
|
|
| |
| local tex_dot_index = strpos("`tex_file_suffix'",".") |
|
|
| |
| if `tex_dot_index' == 0 local tex_file_suffix "" |
|
|
| |
| |
| while `tex_dot_index' > 0 { |
|
|
| |
| local tex_file_suffix = substr("`tex_file_suffix'", `tex_dot_index' + 1, .) |
|
|
| |
| local tex_dot_index = strpos("`tex_file_suffix'",".") |
| } |
|
|
| |
| if "`tex_file_suffix'" == "" { |
|
|
| local savetex `"`savetex'.tex"' |
| } |
|
|
| |
| else if !("`tex_file_suffix'" == "tex" | "`tex_file_suffix'" == "txt") { |
|
|
| noi display as error "{phang}The file format specified in savetex(`savetex') is other than .tex or .txt. Only those two formats are allowed. If no format is specified .tex is the default. If you have a . in your file path, for example in a folder name, then you must specify the file extension .tex or .txt.{p_end}" |
| error 198 |
| } |
|
|
| if `CAPTION_USED' { |
|
|
| |
| local texcaption : subinstr local texcaption "%" "\%" , all |
| local texcaption : subinstr local texcaption "_" "\_" , all |
| local texcaption : subinstr local texcaption "&" "\&" , all |
|
|
| } |
| } |
|
|
| } |
| else if `SAVE_BROWSE_USED' { |
|
|
| noi display as error "{phang}Option savepreserve may only be used in combination with option save(){p_end}" |
| error 198 |
| } |
|
|
| |
| if `SAVE_TEX_USED' { |
|
|
| |
| if `NOTEWIDTH_USED' { |
|
|
| if `texnotewidth' <= 0 { |
|
|
| noi display as error `"{phang}The value specified in texnotewidth(`texnotewidth') is non-positive. Only positive numbers are allowed. For more information, {net "from http://en.wikibooks.org/wiki/LaTeX/Lengths.smcl":check LaTeX lengths manual}.{p_end}"' |
| error 198 |
| } |
| } |
|
|
| |
| if `LABEL_USED' { |
|
|
| local label_words : word count `texlabel' |
|
|
| if `label_words' != 1 { |
|
|
| noi display as error `"{phang}The value specified in texlabel(`texlabel') is not allowed. For more information, {browse "https://en.wikibooks.org/wiki/LaTeX/Labels_and_Cross-referencing":check LaTeX labels manual}.{p_end}"' |
| error 198 |
| } |
|
|
| } |
|
|
| if (`LABEL_USED' | `CAPTION_USED') { |
|
|
| if `TEXDOC_USED' == 0 { |
|
|
| noi display as error "{phang}Options texlabel and texcaption may only be used in combination with option texdocument {p_end}" |
| error 198 |
| } |
| } |
|
|
| if `TEXCOLWIDTH_USED' { |
|
|
| |
| local texcolwidth_unit = substr("`texcolwidth'",-2,2) |
| if !inlist("`texcolwidth_unit'","cm","mm","pt","in","ex","em") { |
| noi display as error `"{phang}Option texcolwidth is incorrectly specified. Column width unit must be one of "cm", "mm", "pt", "in", "ex" or "em". For more information, {browse "https://en.wikibooks.org/wiki/LaTeX/Lengths":check LaTeX lengths manual}.{p_end}"' |
| error 198 |
| } |
|
|
| |
| local texcolwidth_value = subinstr("`texcolwidth'","`texcolwidth_unit'","",.) |
| capture confirm number `texcolwidth_value' |
| if _rc & inlist("`texcolwidth_unit'","cm","mm","pt","in","ex","em") { |
| noi display as error "{phang}Option texcolwidth is incorrectly specified. Column width value must be numeric. See {help iebaltab:iebaltab help}. {p_end}" |
| error 198 |
| } |
| } |
|
|
| if `TEXVSPACE_USED' { |
|
|
| |
| local vspace_unit = substr("`texvspace'",-2,2) |
| if !inlist("`vspace_unit'","cm","mm","pt","in","ex","em") { |
| noi display as error `"{phang}Option texvspace is incorrectly specified. Vertical space unit must be one of "cm", "mm", "pt", "in", "ex" or "em". For more information, {browse "https://en.wikibooks.org/wiki/LaTeX/Lengths":check LaTeX lengths manual}.{p_end}"' |
| error 198 |
| } |
|
|
| |
| local vspace_value = subinstr("`texvspace'","`vspace_unit'","",.) |
| capture confirm number `vspace_value' |
| if _rc & inlist("`vspace_unit'","cm","mm","pt","in","ex","em") { |
| noi display as error "{phang}Option texvspace is incorrectly specified. Vertical space value must be numeric. See {help iebaltab:iebaltab help}. {p_end}" |
| error 198 |
| } |
| } |
| } |
|
|
| |
| else if `NOTEWIDTH_USED' | `LABEL_USED' | `CAPTION_USED' | `TEXDOC_USED' | `TEXVSPACE_USED' | `TEXCOLWIDTH_USED' { |
|
|
| noi display as error "{phang}Options texnotewidth, texdocument, texlabel, texcaption, texvspace and texcolwidth may only be used in combination with option savetex(){p_end}" |
| error 198 |
|
|
| } |
|
|
| |
| if (`SAVE_USED' + `BROWSE_USED' + `SAVE_TEX_USED' < 1) { |
|
|
| |
| noi display as error "{phang}Either option save() or option savetex() or option browse must be used. Note that option browse drops all data in memory and it is not possible to restore it afterwards. Use preserve/restore, tempfiles or save data to disk before using the otion browse." |
| error |
| } |
| |
| |
|
|
|
|
| |
|
|
| |
| |
|
|
|
|
| |
| |
| if !`ORDER_USED' & `CONTROL_USED' local order `control' |
|
|
| |
| |
| |
| local order_code_rest : list GRP_CODE_LEVELS - order |
|
|
|
|
| |
| |
| |
| |
| |
| local ORDER_OF_GROUPS `order' `order_code_rest' |
|
|
|
|
| |
| |
|
|
| |
|
|
| |
| |
|
|
| |
| local grpLabels_final "" |
|
|
| |
| foreach groupCode of local ORDER_OF_GROUPS { |
|
|
| |
| local grpLabelPos : list posof "`groupCode'" in grpLabelCodes |
|
|
| |
| if `grpLabelPos' != 0 { |
|
|
| |
| local group_label : word `grpLabelPos' of `grpLabelLables' |
|
|
| |
| local grpLabels_final `" `grpLabels_final' "`group_label'" "' |
| } |
|
|
| |
| |
| else if `NOGRPLABEL_USED' | !`GRPVAR_HAS_VALUE_LABEL' { |
|
|
| |
| local grpLabels_final `" `grpLabels_final' "`groupCode'" "' |
|
|
| } |
|
|
| |
| else { |
|
|
| |
| local gprVar_valueLabel : label `GRPVAR_VALUE_LABEL' `groupCode' |
|
|
| |
| local grpLabels_final `" `grpLabels_final' "`gprVar_valueLabel'" "' |
|
|
| } |
| } |
|
|
|
|
|
|
|
|
| |
| |
|
|
| |
|
|
| |
| |
|
|
| local rowLabelsFinal "" |
|
|
| foreach balancevar of local balancevars { |
|
|
| |
| |
| |
| local rowLabPos : list posof "`balancevar'" in rowLabelNames |
|
|
| if `rowLabPos' != 0 { |
|
|
| |
| local row_label : word `rowLabPos' of `rowLabelLabels' |
|
|
| |
| local rowLabels_final `" `rowLabels_final' "`row_label'" "' |
|
|
| } |
| |
| else if `ROWVARLABEL_USED' { |
|
|
| |
| local var_label : variable label `balancevar' |
|
|
| |
| local var_label = trim("`var_label'") |
|
|
| |
| if "`var_label'" != "" { |
|
|
| |
| local rowLabels_final `" `rowLabels_final' "`var_label'" "' |
| } |
| |
| else { |
|
|
| |
| local rowLabels_final `" `rowLabels_final' "`balancevar'" "' |
| } |
| } |
| |
| else { |
|
|
| |
| local rowLabels_final `" `rowLabels_final' "`balancevar'" "' |
| } |
| } |
|
|
| } |
| |
| |
|
|
| |
|
|
| |
| |
|
|
|
|
|
|
| |
| |
| local titlerow1 "" |
| local titlerow2 "" |
| local titlerow3 `""Variable""' |
|
|
|
|
| |
| |
| local texrow1 "" |
| local texrow2 "" |
| local texrow3 `"Variable"' |
|
|
| |
| |
| local variance_type "SE" |
| if `STDEV_USED' == 1 local variance_type "SD" |
|
|
| |
| if "`vce_type'" != "cluster" { |
| local N_title "N" |
| } |
| else { |
| local N_title "N/[Clusters]" |
| } |
|
|
| |
| |
|
|
| |
| |
| tempvar groupOrder |
| gen `groupOrder' = . |
|
|
| |
| forvalues groupOrderNum = 1/`GRPVAR_NUM_GROUPS' { |
|
|
| |
| local groupLabel : word `groupOrderNum' of `grpLabels_final' |
| local groupCode : word `groupOrderNum' of `ORDER_OF_GROUPS' |
|
|
| |
| local texGroupLabel : subinstr local groupLabel "%" "\%" , all |
| local texGroupLabel : subinstr local texGroupLabel "_" "\_" , all |
| local texGroupLabel : subinstr local texGroupLabel "&" "\&" , all |
| local texGroupLabel : subinstr local texGroupLabel "\$" "\\\\\\\$" , all |
|
|
| |
| if `ONEROW_USED' == 1 local onerow_`groupOrderNum' "" |
|
|
| |
| replace `groupOrder' = `groupOrderNum' if `grpvar' == `groupCode' |
|
|
| |
| if `ONEROW_USED' == 0 { |
|
|
| local titlerow1 `"`titlerow1' _tab "" _tab " (`groupOrderNum') " "' |
| local titlerow2 `"`titlerow2' _tab "" _tab "`groupLabel'" "' |
| local titlerow3 `"`titlerow3' _tab "`N_title'" _tab "Mean/`variance_type'" "' |
|
|
|
|
| local texrow1 `"`texrow1' & \multicolumn{2}{c}{(`groupOrderNum')} "' |
| local texrow2 `"`texrow2' & \multicolumn{2}{c}{`texGroupLabel'} "' |
| local texrow3 `"`texrow3' & `N_title' & Mean/`variance_type' "' |
|
|
| } |
| else { |
|
|
| local titlerow1 `"`titlerow1' _tab " (`groupOrderNum') " "' |
| local titlerow2 `"`titlerow2' _tab "`groupLabel'" "' |
| local titlerow3 `"`titlerow3' _tab "Mean/`variance_type'" "' |
|
|
| local texrow1 `"`texrow1' & (`groupOrderNum') "' |
| local texrow2 `"`texrow2' & `texGroupLabel' "' |
| local texrow3 `"`texrow3' & Mean/`variance_type' "' |
|
|
| } |
|
|
| } |
|
|
| |
| |
|
|
| if `TOTAL_USED' { |
|
|
| |
| local totalColNumber = `GRPVAR_NUM_GROUPS' + 1 |
|
|
| |
| if `ONEROW_USED' == 1 local onerow_tot "" |
|
|
| local tot_label Total |
| if `TOTALLABEL_USED' local tot_label `totallabel' |
|
|
| |
| local tex_tot_label : subinstr local tot_label "%" "\%" , all |
| local tex_tot_label : subinstr local tex_tot_label "_" "\_" , all |
| local tex_tot_label : subinstr local tex_tot_label "&" "\&" , all |
| local tex_tot_label : subinstr local tex_tot_label "\$" "\\\\\$" , all |
|
|
| |
| if `ONEROW_USED' == 0 { |
|
|
| local titlerow1 `"`titlerow1' _tab "" _tab " (`totalColNumber') " "' |
| local titlerow2 `"`titlerow2' _tab "" _tab "`tot_label'" "' |
| local titlerow3 `"`titlerow3' _tab "`N_title'" _tab "Mean/`variance_type'" "' |
|
|
| local texrow1 `"`texrow1' & \multicolumn{2}{c}{(`totalColNumber')}"' |
| local texrow2 `"`texrow2' & \multicolumn{2}{c}{`tex_tot_label'} "' |
| local texrow3 `"`texrow3' & `N_title' & Mean/`variance_type' "' |
| } |
| else { |
|
|
| local titlerow1 `"`titlerow1' _tab " (`totalColNumber') " "' |
| local titlerow2 `"`titlerow2' _tab "`tot_label'" "' |
| local titlerow3 `"`titlerow3' _tab "Mean/`variance_type'" "' |
|
|
| local texrow1 `"`texrow1' & (`totalColNumber') "' |
| local texrow2 `"`texrow2' & `tex_tot_label' "' |
| local texrow3 `"`texrow3' & Mean/`variance_type' "' |
|
|
| } |
| } |
|
|
| |
| |
|
|
| if `TTEST_USED' | `NORMDIFF_USED' { |
|
|
| if `CONTROL_USED' { |
|
|
| iecontrolheader "`control'" "`ORDER_OF_GROUPS'" "`GRPVAR_NUM_GROUPS'" |
| `TTEST_USED' `PTTEST_USED' `NORMDIFF_USED' |
| `" `titlerow1' "' `" `titlerow2' "' `" `titlerow3' "' `" `texrow3' "' |
| } |
| else { |
|
|
| ienocontrolheader "`GRPVAR_NUM_GROUPS'" |
| `TTEST_USED' `PTTEST_USED' `NORMDIFF_USED' |
| `" `titlerow1' "' `" `titlerow2' "' `" `titlerow3' "' `" `texrow3' "' |
|
|
| } |
|
|
| local titlerow1 `"`r(titlerow1)'"' |
| local titlerow2 `"`r(titlerow2)'"' |
| local titlerow3 `"`r(titlerow3)'"' |
| local texrow3 `"`r(texrow3)'"' |
| local ttest_pairs `"`r(ttest_pairs)'"' |
|
|
|
|
| local testPairCount : list sizeof ttest_pairs |
|
|
| if `testPairCount' > 0 { |
|
|
| if `TTEST_USED' { |
| local texrow1 `" `texrow1' & \multicolumn{`testPairCount'}{c}{t-test} "' |
|
|
| if `PTTEST_USED' == 1 { |
| local texrow2 `"`texrow2' & \multicolumn{`testPairCount'}{c}{p-value} "' |
| } |
| else { |
| local texrow2 `"`texrow2' & \multicolumn{`testPairCount'}{c}{Difference} "' |
| } |
| } |
|
|
| if `NORMDIFF_USED' { |
| local texrow1 `"`texrow1' & \multicolumn{`testPairCount'}{c}{Normalized} "' |
| local texrow2 `"`texrow2' & \multicolumn{`testPairCount'}{c}{difference} "' |
| } |
| } |
| |
| } |
|
|
| |
| |
|
|
| if `FEQTEST_USED' { |
|
|
| local titlerow1 `"`titlerow1' _tab "F-test""' |
| local titlerow2 `"`titlerow2' _tab "for joint""' |
| local titlerow3 `"`titlerow3' _tab "orthogonality""' |
|
|
| local texrow1 `" `texrow1' & \multicolumn{1}{c}{F-test} "' |
| local texrow2 `" `texrow2' & \multicolumn{1}{c}{for joint}"' |
| local texrow3 `" `texrow3' & \multicolumn{1}{c}{orthogonality}"' |
| } |
|
|
|
|
| |
| |
|
|
| |
| tempname textname |
| tempfile textfile |
|
|
| |
| cap file close `textname' |
| file open `textname' using "`textfile'", text write replace |
| file write `textname' |
| `titlerow1' _n |
| `titlerow2' _n |
| `titlerow3' _n |
| file close `textname' |
|
|
| |
| |
|
|
| |
| if `TEXCOLWIDTH_USED' == 0 local colstring l |
| else local colstring p{`texcolwidth'} |
|
|
| forvalues repeat = 1/`NUM_COL_GRP_TOT' { |
|
|
| |
| local colstring "`colstring'c" |
| |
| if !`ONEROW_USED'{ |
| local colstring "`colstring'c" |
| } |
| } |
|
|
| |
| if `TTEST_USED' { |
| forvalues repeat = 1/`testPairCount' { |
| local colstring "`colstring'c" |
| } |
| } |
|
|
| |
| if `FEQTEST_USED'{ |
| local colstring "`colstring'c" |
| } |
|
|
| |
| if `NORMDIFF_USED'{ |
| forvalues repeat = 1/`testPairCount' { |
| local colstring "`colstring'c" |
| } |
| } |
|
|
| |
| tempname texname |
| tempfile texfile |
|
|
| |
| |
| capture file close `texname' |
|
|
| if `TEXDOC_USED' { |
|
|
| file open `texname' using "`texfile'", text write replace |
| file write `texname' |
| "%%% Table created in Stata by iebaltab (https://github.com/worldbank/ietoolkit)" _n |
| "" _n |
| "\documentclass{article}" _n |
| "" _n |
| "% ----- Preamble " _n |
| "\usepackage[utf8]{inputenc}" _n |
| "\usepackage{adjustbox}" _n |
|
|
| file write `texname' |
| "% ----- End of preamble " _n |
| "" _n |
| " \begin{document}" _n |
| "" _n |
| "\begin{table}[!htbp]" _n |
| "\centering" _n |
|
|
| |
| if `CAPTION_USED' { |
|
|
| file write `texname' `"\caption{`texcaption'}"' _n |
|
|
| } |
|
|
| |
| if `LABEL_USED' { |
|
|
| file write `texname' `"\label{`texlabel'}"' _n |
|
|
| } |
|
|
| file write `texname' "\begin{adjustbox}{max width=\textwidth}" _n |
| file close `texname' |
|
|
| } |
|
|
| file open `texname' using "`texfile'", text write append |
| file write `texname' |
| "\begin{tabular}{@{\extracolsep{5pt}}`colstring'}" _n |
| "\\[-1.8ex]\hline \hline \\[-1.8ex]" _n |
| file close `texname' |
|
|
| |
| capture file close `texname' |
| file open `texname' using "`texfile'", text write append |
|
|
| file write `texname' |
| "`texrow1' \\" _n |
| "`texrow2' \\" _n |
| "`texrow3' \\ \hline \\[-1.8ex] " _n |
| file close `texname' |
|
|
|
|
| |
| |
|
|
| |
| |
|
|
| |
| |
|
|
| |
|
|
| |
| |
|
|
| if !`FIX_EFFECT_USED' { |
|
|
| |
| |
| |
| |
| tempvar fixedeffect |
| gen `fixedeffect' = 1 |
| } |
|
|
| |
| |
|
|
| if `VCE_USED' { |
|
|
| |
| |
| |
| local error_estm vce(`vce') |
|
|
| } |
|
|
| |
| |
|
|
| local weight_option "" |
|
|
| if `WEIGHT_USED' { |
|
|
| |
| local weight_option "[`weight_type' = `weight_var']" |
|
|
| } |
|
|
|
|
| |
|
|
| |
| local warn_means_num 0 |
| local warn_ftest_num 0 |
|
|
| |
| local warn_joint_novar_num 0 |
| local warn_joint_lovar_num 0 |
| local warn_joint_robus_num 0 |
|
|
|
|
| |
|
|
| local tex_line_space 0pt |
|
|
| foreach balancevar in `balancevars' { |
|
|
| |
| gettoken row_label rowLabels_final : rowLabels_final |
|
|
| |
| local tableRowUp `""`row_label'""' |
| local tableRowDo `" "' |
|
|
| |
| local texrow_label : subinstr local row_label "%" "\%" , all |
| local texrow_label : subinstr local texrow_label "_" "\_" , all |
| local texrow_label : subinstr local texrow_label "[" "{[}" , all |
| local texrow_label : subinstr local texrow_label "&" "\&" , all |
| local texrow_label : subinstr local texrow_label "\$" "\\\\\\\$" , all |
|
|
| local texRow `""`texrow_label'""' |
|
|
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| local replaceoptions |
|
|
| |
| if `BALMISS_USED' local replaceoptions `" `replaceoptions' replacetype("`balmiss'") "' |
| if `BALMISSREG_USED' local replaceoptions `" `replaceoptions' replacetype("`balmissreg'") regonly "' |
|
|
| |
| if "`balmiss'" == "groupmean" local replaceoptions `" `replaceoptions' groupvar(`grpvar') groupcodes("`GRP_CODE_LEVELS'") "' |
| if "`balmissreg'" == "groupmean" local replaceoptions `" `replaceoptions' groupvar(`grpvar') groupcodes("`GRP_CODE_LEVELS'") "' |
|
|
| |
| if `MISSMINMEAN_USED' == 1 local replaceoptions `" `replaceoptions' minobsmean(`missminmean') "' |
| if `MISSMINMEAN_USED' == 0 local replaceoptions `" `replaceoptions' minobsmean(10) "' |
|
|
| |
| if (`BALMISS_USED' | `BALMISSREG_USED') iereplacemiss `balancevar', `replaceoptions' |
|
|
|
|
| |
|
|
| forvalues groupNumber = 1/`GRPVAR_NUM_GROUPS' { |
|
|
| reg `balancevar' if `groupOrder' == `groupNumber' `weight_option', `error_estm' |
|
|
| |
| local N_`groupNumber' = e(N) |
| local N_`groupNumber' : display %9.0f `N_`groupNumber'' |
|
|
| |
| if "`vce_type'" == "cluster" { |
|
|
| local N_clust_`groupNumber' = e(N_clust) |
| local N_clust_`groupNumber' : display %9.0f `N_clust_`groupNumber'' |
| local N_clust_`groupNumber' = trim("`N_clust_`groupNumber''") |
| local N_clustex_`groupNumber' = "{[}`N_clust_`groupNumber'']" |
| local N_clust_`groupNumber' = "[`N_clust_`groupNumber'']" |
| } |
|
|
| |
| local mean_`groupNumber' = _b[_cons] |
| local se_`groupNumber' = _se[_cons] |
|
|
| local di_mean_`groupNumber' : display `diformat' `mean_`groupNumber'' |
|
|
| |
| if `STDEV_USED' == 0 { |
| |
| local di_var_`groupNumber' : display `diformat' `se_`groupNumber'' |
| } |
| else { |
| |
| local sd_`groupNumber' = `se_`groupNumber'' * sqrt(`N_`groupNumber'') |
| |
| local di_var_`groupNumber' : display `diformat' `sd_`groupNumber'' |
| } |
|
|
| |
| local N_`groupNumber' =trim("`N_`groupNumber''") |
| local di_mean_`groupNumber' =trim("`di_mean_`groupNumber''") |
| local di_var_`groupNumber' =trim("`di_var_`groupNumber''") |
|
|
| |
| if `ONEROW_USED' == 0 { |
|
|
| local tableRowUp `"`tableRowUp' _tab "`N_`groupNumber''" _tab "`di_mean_`groupNumber''" "' |
| local tableRowDo `"`tableRowDo' _tab "`N_clust_`groupNumber''" _tab "[`di_var_`groupNumber'']" "' |
|
|
| if `SHOW_NCLUSTER' == 0 { |
| local texRow `"`texRow' " & `N_`groupNumber'' & \begin{tabular}[t]{@{}c@{}} `di_mean_`groupNumber'' \\ (`di_var_`groupNumber'') \end{tabular}" "' |
| } |
| if `SHOW_NCLUSTER' == 1 { |
| local texRow `"`texRow' " & \begin{tabular}[t]{@{}c@{}} `N_`groupNumber'' \\ `N_clustex_`groupNumber'' \end{tabular} & \begin{tabular}[t]{@{}c@{}} `di_mean_`groupNumber'' \\ (`di_var_`groupNumber'') \end{tabular}" "' |
| } |
| } |
| else { |
|
|
| |
| if "`onerow_`groupNumber''" == "" { |
| |
| local onerow_`groupNumber' = `N_`groupNumber'' |
| } |
| |
| else if !(`onerow_`groupNumber'' == `N_`groupNumber'') { |
|
|
| |
| if (`onerow_`groupNumber'' <= `N_`groupNumber'') { |
| local onerow_`groupNumber' = `N_`groupNumber'' |
| } |
|
|
| |
| |
| |
| |
| |
| } |
|
|
|
|
| |
| if "`vce_type'" == "cluster" { |
|
|
| if "`oneclstrow_`groupNumber''" == "" { |
| |
| local oneclstrow_`groupNumber' = `N_clust_`groupNumber'' |
| } |
| |
| else if !(`oneclstrow_`groupNumber'' == `N_clust_`groupNumber'') { |
|
|
| |
| noi display as error "{phang}The number of clusters for `balancevar' is differenet compared to other balance variables within the same group. You can therefore not use the option onerow. Run the command without the option onerow to see which group does not have the same number of clusters with non-missing values across all balance variables.{p_end}" |
| error 198 |
| } |
| } |
|
|
| |
| local tableRowUp `"`tableRowUp' _tab "`di_mean_`groupNumber''" "' |
| local tableRowDo `"`tableRowDo' _tab "[`di_var_`groupNumber'']" "' |
|
|
| local texRow `"`texRow' " & \begin{tabular}[t]{@{}c@{}} `di_mean_`groupNumber'' \\ (`di_var_`groupNumber'') \end{tabular}" "' |
| } |
|
|
| } |
|
|
| if `TOTAL_USED' { |
|
|
| reg `balancevar' `weight_option', `error_estm' |
|
|
| local N_tot = e(N) |
| local N_tot : display %9.0f `N_tot' |
|
|
| |
| if "`vce_type'" == "cluster" { |
|
|
| local N_clust_tot = e(N_clust) |
| local N_clust_tot : display %9.0f `N_clust_tot' |
| local N_clust_tot = trim("`N_clust_tot'") |
| local N_clustex_tot = "{[}`N_clust_tot']" |
| local N_clust_tot = "[`N_clust_tot']" |
| } |
|
|
|
|
| |
| local mean_tot = _b[_cons] |
| local se_tot = _se[_cons] |
|
|
| local mean_tot : display `diformat' `mean_tot' |
|
|
| |
| if `STDEV_USED' == 0 { |
| |
| local var_tot : display `diformat' `se_tot' |
| } |
| else { |
| |
| local sd_tot = `se_tot' * sqrt(`N_tot') |
| |
| local var_tot : display `diformat' `sd_tot' |
|
|
| } |
|
|
| |
| local N_tot =trim("`N_tot'") |
| local mean_tot =trim("`mean_tot'") |
| local var_tot =trim("`var_tot'") |
|
|
|
|
|
|
| |
| if `ONEROW_USED' == 0 { |
|
|
| local tableRowUp `"`tableRowUp' _tab "`N_tot'" _tab "`mean_tot'" "' |
| local tableRowDo `"`tableRowDo' _tab "`N_clust_tot'" _tab "[`var_tot']" "' |
|
|
| if `SHOW_NCLUSTER' == 0 { |
| local texRow `"`texRow' " & `N_tot' & \begin{tabular}[t]{@{}c@{}} `mean_tot' \\ (`var_tot') \end{tabular}" "' |
| } |
| if `SHOW_NCLUSTER' == 1 { |
| local texRow `"`texRow' " & \begin{tabular}[t]{@{}c@{}} `N_tot' \\ `N_clustex_tot' \end{tabular} & \begin{tabular}[t]{@{}c@{}} `mean_tot' \\ (`var_tot') \end{tabular}" "' |
| } |
| } |
| else { |
|
|
| |
| if "`onerow_tot'" == "" { |
| |
| local onerow_tot = `N_tot' |
| } |
| |
| else if !(`onerow_tot' == `N_tot') { |
|
|
| |
| noi display as error "{phang}The number of observations for all groups are not the same for `balancevar' compare to at least one other balance variables. Run the command without the option onerow to see which group does not have the same number of observations with non-missing values across all balance variables. This happened in the total column which can be an indication of a serious bug. Please email this erro message to kbjarkefur@worldbank.org{p_end}" |
| error 198 |
| } |
|
|
| |
| if "`vce_type'" == "cluster" { |
|
|
| if "`oneclstrow_tot'" == "" { |
| |
| local oneclstrow_tot = `N_clust_tot' |
| } |
| |
| else if !(`oneclstrow_tot' == `N_clust_tot') { |
|
|
| |
| noi display as error "{phang}The number of clusters fora ll groups for `balancevar' is differenet compared to other balance variables. You can therefore not use the option onerow. Run the command without the option onerow to see which balance variable does not have the same number of clusters with non-missing values as the other balance variables.{p_end}" |
| error 198 |
| } |
| } |
|
|
|
|
| |
| local tableRowUp `"`tableRowUp' _tab "`mean_tot'" "' |
| local tableRowDo `"`tableRowDo' _tab "[`var_tot']" "' |
|
|
| local texRow `"`texRow' " & \begin{tabular}[t]{@{}c@{}} `mean_tot' \\ (`var_tot') \end{tabular}" "' |
| } |
| } |
|
|
| |
|
|
| if `TTEST_USED' { |
|
|
| foreach ttest_pair of local ttest_pairs { |
|
|
| |
| |
| local undscr_pos = strpos("`ttest_pair'","_") |
| local first_group = substr("`ttest_pair'",1,`undscr_pos'-1) |
| local second_group = substr("`ttest_pair'", `undscr_pos'+1,.) |
|
|
| |
| local diff_`ttest_pair' = `mean_`first_group'' - `mean_`second_group'' |
|
|
| |
| |
| |
| |
| |
| tempvar tempvar_thisGroupInPair |
| gen `tempvar_thisGroupInPair' = . |
| replace `tempvar_thisGroupInPair' = 0 if `groupOrder' == `first_group' |
| replace `tempvar_thisGroupInPair' = 1 if `groupOrder' == `second_group' |
|
|
| |
| |
| |
| |
| |
| |
| if "`error_estm'" != "vce(robust)" local mean_error_estm `error_estm' |
| mean `balancevar', over(`tempvar_thisGroupInPair') `mean_error_estm' |
| mat var = e(V) |
| local varloc = max(var[1,1],var[2,2]) |
|
|
| |
| reg `balancevar' `tempvar_thisGroupInPair' `covariates' i.`fixedeffect' `weight_option', `error_estm' |
|
|
|
|
| |
| if `varloc' == 0 { |
|
|
| local warn_means_num = `warn_means_num' + 1 |
|
|
| local warn_means_name`warn_means_num' "t-test" |
| local warn_means_group`warn_means_num' "(`first_group')-(`second_group')" |
| local warn_means_bvar`warn_means_num' "`balancevar'" |
|
|
| local tableRowUp `" `tableRowUp' _tab "N/A" "' |
| local tableRowDo `" `tableRowDo' _tab " " "' |
|
|
| local texRow `" `texRow' " & N/A" "' |
|
|
| } |
|
|
| else { |
|
|
| |
| test `tempvar_thisGroupInPair' |
| local pttest = r(p) |
|
|
|
|
| |
| if `PTTEST_USED' == 1 { |
|
|
| local ttest_output = `pttest' |
| } |
| |
| else { |
|
|
| local ttest_output = `diff_`ttest_pair'' |
| } |
|
|
| |
| local ttest_output : display `diformat' `ttest_output' |
|
|
| |
| foreach ttest_p_level in `p1star' `p2star' `p3star' { |
|
|
| if `pttest' < `ttest_p_level' local ttest_output "`ttest_output'*" |
| } |
|
|
| |
| local tableRowUp `" `tableRowUp' _tab "`ttest_output'" "' |
| local tableRowDo `" `tableRowDo' _tab " " "' |
|
|
| local texRow `" `texRow' " & `ttest_output'" "' |
| } |
| } |
| } |
|
|
| |
|
|
| if `NORMDIFF_USED' { |
|
|
| foreach normdiff_pair of local ttest_pairs { |
|
|
| |
| |
| local undscr_pos = strpos("`normdiff_pair'","_") |
| local first_group = substr("`normdiff_pair'",1,`undscr_pos'-1) |
| local second_group = substr("`normdiff_pair'", `undscr_pos'+1,.) |
|
|
| |
| local diff_`normdiff_pair' = `mean_`first_group'' - `mean_`second_group'' |
|
|
| |
| sum `balancevar' if inlist(`groupOrder',`first_group',`second_group') |
|
|
| |
| if r(sd) == 0 { |
|
|
| local warn_means_num = `warn_means_num' + 1 |
|
|
| local warn_means_name`warn_means_num' "Norm diff" |
| local warn_means_group`warn_means_num' "(`first_group')-(`second_group')" |
| local warn_means_bvar`warn_means_num' "`balancevar'" |
|
|
| local tableRowUp `" `tableRowUp' _tab "N/A" "' |
| local tableRowDo `" `tableRowDo' _tab " " "' |
|
|
| local texRow `" `texRow' " & N/A" "' |
|
|
| } |
|
|
| else { |
| |
| local normdiff_`normdiff_pair' = `diff_`normdiff_pair''/r(sd) |
|
|
| |
| local normdiff_output : display `diformat' `normdiff_`normdiff_pair'' |
|
|
| |
| local tableRowUp `" `tableRowUp' _tab "`normdiff_output'" "' |
| local tableRowDo `" `tableRowDo' _tab " " "' |
|
|
| local texRow `" `texRow' " & `normdiff_output'" "' |
| } |
| } |
| } |
|
|
| |
|
|
| if `FEQTEST_USED' { |
|
|
| |
| reg `balancevar' i.`grpvar' `covariates' i.`fixedeffect' `weight_option', `error_estm' |
|
|
| |
| |
| local 1st_level = strpos("`GRP_CODE_LEVELS'"," ") + 1 |
| local FEQTEST_CODE_LEVELS = substr("`GRP_CODE_LEVELS'",`1st_level',.) |
|
|
| |
| local ftest_input "" |
| foreach grpCode of local FEQTEST_CODE_LEVELS { |
| local ftest_input = " `ftest_input' `grpCode'.`grpvar'=" |
| } |
|
|
| test `ftest_input' 0 |
| local pfeqtest = r(p) |
| local ffeqtest = r(F) |
|
|
| |
| |
| if "`ffeqtest'" == "." { |
|
|
| local warn_ftest_num = `warn_ftest_num' + 1 |
|
|
| local warn_ftest_bvar`warn_ftest_num' "`balancevar'" |
|
|
| local tableRowUp `" `tableRowUp' _tab "N/A" "' |
| local tableRowDo `" `tableRowDo' _tab " " "' |
|
|
| local texRow `" `texRow' " & N/A" "' |
| } |
|
|
| else { |
|
|
| |
|
|
| |
| if `PFTEST_USED' { |
|
|
| local feqtest_output = `pfeqtest' |
| } |
| |
| else { |
|
|
| local feqtest_output = `ffeqtest' |
| } |
|
|
|
|
| |
| local feqtest_output : display `diformat' `feqtest_output' |
|
|
| |
| foreach feqtest_p_level in `p1star' `p2star' `p3star' { |
|
|
| if `pfeqtest' < `feqtest_p_level' local feqtest_output `feqtest_output'* |
| } |
|
|
| |
| local tableRowUp `" `tableRowUp' _tab "`feqtest_output'" "' |
| local tableRowDo `" `tableRowDo' _tab " " "' |
|
|
| local texRow `" `texRow' " & `feqtest_output'" "' |
| } |
| } |
|
|
|
|
| |
| file open `textname' using "`textfile'", text write append |
| file write `textname' |
| `tableRowUp' _n |
| `tableRowDo' _n |
| file close `textname' |
|
|
| file open `texname' using "`texfile'", text write append |
| file write `texname' |
| `texRow' " \rule{0pt}{`tex_line_space'}\\" _n |
| file close `texname' |
|
|
| |
| if `TEXVSPACE_USED' == 0 local tex_line_space 3ex |
| else local tex_line_space `texvspace' |
| } |
|
|
|
|
|
|
| |
|
|
| if `ONEROW_USED' == 1 { |
|
|
| |
| local tableRowN `""N""' |
| local texRowN `"N"' |
|
|
| local tableRowClstr `""Clusters""' |
| local texRowClstr `"Clusters"' |
|
|
| |
| forvalues groupOrderNum = 1/`GRPVAR_NUM_GROUPS' { |
|
|
| |
| local tableRowN `" `tableRowN' _tab "`onerow_`groupOrderNum''" "' |
| local texRowN `" `texRowN' & `onerow_`groupOrderNum'' "' |
|
|
| local tableRowClstr `" `tableRowClstr' _tab "`oneclstrow_`groupOrderNum''" "' |
| local texRowClstr `" `texRowClstr' & `oneclstrow_`groupOrderNum'' "' |
|
|
| } |
|
|
| if `TOTAL_USED' { |
|
|
| |
| local tableRowN `" `tableRowN' _tab "`onerow_tot'" "' |
| local texRowN `" `texRowN' & `onerow_tot' "' |
|
|
| local tableRowClstr `" `tableRowClstr' _tab "`oneclstrow_tot'" "' |
| local texRowClstr `" `texRowClstr' & `oneclstrow_tot' "' |
| } |
|
|
| |
| file open `textname' using "`textfile'", text write append |
| file write `textname' `tableRowN' _n |
| if "`vce_type'" == "cluster" file write `textname' `tableRowClstr' _n |
| file close `textname' |
|
|
| file open `texname' using "`texfile'", text write append |
| file write `texname' " `texRowN' \rule{0pt}{`tex_line_space'} \\" _n |
| if "`vce_type'" == "cluster" file write `texname' " `texRowClstr' \\" _n |
| file close `texname' |
| } |
|
|
| |
| |
|
|
| |
|
|
| |
| |
|
|
| if `FTEST_USED' { |
|
|
| if `ONEROW_USED' == 0 { |
| local ftestMulticol = 1 + (2*`NUM_COL_GRP_TOT') |
| } |
| else { |
| local ftestMulticol = 1 + `NUM_COL_GRP_TOT' |
| } |
|
|
|
|
| if `PFTEST_USED' { |
| local Fstat_row `" "F-test of joint significance (p-value)" "' |
| local Fstat_texrow `" "\multicolumn{`ftestMulticol'}{@{} l}{F-test of joint significance (p-value)}" "' |
| } |
| else { |
| local Fstat_row `" "F-test of joint significance (F-stat)" "' |
| local Fstat_texrow `" "\multicolumn{`ftestMulticol'}{@{} l}{F-test of joint significance (F-stat)}" "' |
| } |
|
|
| local Fobs_row `" "F-test, number of observations" "' |
| local Fobs_texrow `" "\multicolumn{`ftestMulticol'}{@{} l}{F-test, number of observations}" "' |
|
|
| |
| forvalues groupIteration = 1/`GRPVAR_NUM_GROUPS' { |
|
|
| local Fstat_row `" `Fstat_row' _tab "" "' |
| local Fobs_row `" `Fobs_row' _tab "" "' |
|
|
| |
| if `ONEROW_USED' == 0 { |
| local Fstat_row `" `Fstat_row' _tab "" "' |
| local Fobs_row `" `Fobs_row' _tab "" "' |
|
|
| } |
| } |
|
|
| |
| if `TOTAL_USED' { |
| local Fstat_row `" `Fstat_row' _tab "" "' |
| local Fobs_row `" `Fobs_row' _tab "" "' |
|
|
|
|
| |
| if `ONEROW_USED' == 0 { |
| local Fstat_row `" `Fstat_row' _tab "" "' |
| local Fobs_row `" `Fobs_row' _tab "" "' |
|
|
| } |
| } |
|
|
| |
| local warn_joint_novar_num 0 |
| local warn_joint_lovar_num 0 |
| local warn_joint_robus_num 0 |
| local fmiss_error 0 |
|
|
| |
| foreach ttest_pair of local ttest_pairs { |
|
|
| |
| |
| local undscr_pos = strpos("`ttest_pair'","_") |
| local first_group = substr("`ttest_pair'",1,`undscr_pos'-1) |
| local second_group = substr("`ttest_pair'", `undscr_pos'+1,.) |
|
|
| |
| tempvar tempvar_thisGroupInPair miss |
| gen `tempvar_thisGroupInPair' = . |
| replace `tempvar_thisGroupInPair' = 0 if `groupOrder' == `first_group' |
| replace `tempvar_thisGroupInPair' = 1 if `groupOrder' == `second_group' |
|
|
| |
|
|
| |
| local balvars_comma_seperated |
| foreach balancevar of local balancevars { |
| local balvars_comma_seperated `balvars_comma_seperated' , `balancevar' |
| } |
| |
| local balvars_comma_seperated = subinstr("`balvars_comma_seperated'" ,",","",1) |
| |
| gen `miss' = missing(`balvars_comma_seperated') if !missing(`tempvar_thisGroupInPair') |
|
|
| |
| count if `miss' == 0 |
|
|
| if `r(N)' == 0 { |
| noi di as error "{phang}F-test not possible. All observations are dropped from the f-test regression as no observation in the f-test between (`first_group')-(`second_group') has non-missing values in all balance variables. Disable the f-test option." |
| error 2000 |
| } |
| else if `r(N)' == 1 { |
| noi di as error "{phang}F-test not possible. All but one observation are dropped from the f-test regression as only that one observation in the f-test between (`first_group')-(`second_group') has non-missing values in all balance variables. Disable the f-test option." |
| error 2001 |
| } |
|
|
| |
| count if `miss' == 1 |
|
|
|
|
| if `r(N)' != 0 & `F_MISS_OK' == 0 { |
| local fmiss_error 1 |
| local fmiss_error_list `fmiss_error_list', (`first_group')-(`second_group') |
| } |
|
|
| |
| |
| reg `tempvar_thisGroupInPair' `balancevars' `covariates' i.`fixedeffect' `weight_option', `error_estm' |
|
|
| |
| local reg_F "`e(F)'" |
| local reg_F_N "`e(N)'" |
|
|
| |
| cap testparm `balancevars' |
| local test_F "`r(F)'" |
| local test_F_p "`r(p)'" |
|
|
| |
| |
|
|
| |
| if _rc == 111 { |
|
|
| local warn_joint_novar_num = `warn_joint_novar_num' + 1 |
| local warn_joint_novar`warn_joint_novar_num' "(`first_group')-(`second_group')" |
|
|
| local Fstat_row `" `Fstat_row' _tab "N/A" "' |
| local Fobs_row `" `Fobs_row' _tab "N/A" "' |
|
|
| local Fstat_texrow `" `Fstat_texrow' " & N/A" "' |
| local Fobs_texrow `" `Fobs_texrow' " & N/A" "' |
| } |
|
|
| |
| else if "`test_F'" == "." { |
|
|
| local warn_joint_lovar_num = `warn_joint_lovar_num' + 1 |
| local warn_joint_lovar`warn_joint_lovar_num' "(`first_group')-(`second_group')" |
|
|
| local Fstat_row `" `Fstat_row' _tab "N/A" "' |
| local Fobs_row `" `Fobs_row' _tab "N/A" "' |
|
|
| local Fstat_texrow `" `Fstat_texrow' " & N/A" "' |
| local Fobs_texrow `" `Fobs_texrow' " & N/A" "' |
| } |
|
|
| |
| else if _rc != 0 { |
| noi di as error "F-test not valid. Please report this error to kbjarkefur@worldbank.org" |
| error _rc |
| } |
|
|
| |
| else { |
|
|
| |
| if "`reg_F'" == "." { |
|
|
| local warn_joint_robus_num = `warn_joint_robus_num' + 1 |
| local warn_joint_robus`warn_joint_robus_num' "(`first_group')-(`second_group')" |
| } |
|
|
| |
| if `PFTEST_USED' { |
|
|
| local ftest_output = `test_F_p' |
| } |
| |
| else { |
|
|
| local ftest_output = `test_F' |
| } |
|
|
|
|
| |
| local ftest_output : display `diformat' `ftest_output' |
| local reg_F_N : display %9.0f `reg_F_N' |
|
|
| |
| foreach ftest_p_level in `p1star' `p2star' `p3star' { |
|
|
| if `test_F_p' < `ftest_p_level' local ftest_output `ftest_output'* |
| } |
|
|
| |
| local Fstat_row `" `Fstat_row' _tab "`ftest_output'" "' |
| local Fobs_row `" `Fobs_row' _tab "`reg_F_N'" "' |
|
|
| local Fstat_texrow `" `Fstat_texrow' " & `ftest_output'" "' |
| local Fobs_texrow `" `Fobs_texrow' " & `reg_F_N'" "' |
| } |
| } |
|
|
| |
| |
| if `fmiss_error' == 1 { |
|
|
| |
| local fmiss_error_list = subinstr("`fmiss_error_list'" ,",","",1) |
|
|
| noi di as error "{phang}F-test is possible but perhaps not advisable. Some observations have missing values in some of the balance variables and therfore dropped from the f-stat regression. This happened in the f-tests for the following group(s): [`fmiss_error_list']. Solve this by manually restricting the balance table using if or in, or disable the f-test, or by using option {help iebaltab:balmiss()}. Suppress this error message by using option {help iebaltab:fmissok}" |
| error 416 |
| } |
|
|
|
|
|
|
| |
| |
|
|
| file open `textname' using "`textfile'", text write append |
| file write `textname' `Fstat_row' _n |
| if !`F_NO_OBS' file write `textname' `Fobs_row' _n |
| file close `textname' |
|
|
|
|
| file open `texname' using "`texfile'", text write append |
| file write `texname' "\hline" _n |
| file write `texname' `Fstat_texrow' " \\" _n |
| if !`F_NO_OBS' file write `texname' `Fobs_texrow' " \\" _n |
| file close `texname' |
| } |
|
|
|
|
| |
| |
|
|
| |
|
|
| |
| |
|
|
| local anywarning = max(`warn_means_num',`warn_ftest_num',`warn_joint_novar_num', `warn_joint_lovar_num' ,`warn_joint_robus_num') |
| local anywarning_F = max(`warn_joint_novar_num', `warn_joint_lovar_num' ,`warn_joint_robus_num') |
|
|
|
|
|
|
| if `anywarning' > 0 { |
|
|
| noi di as text "" |
| noi di as error "{hline}" |
| noi di as error "{pstd}Stata issued one or more warnings in relation to the tests in this balance table. Read the warning(s) below carefully before using the values generated for this table.{p_end}" |
| noi di as text "" |
|
|
| if `warn_means_num' > 0 { |
|
|
| noi di as text "{pmore}{bf:Difference-in-Means Tests:} The variance in both groups listed below is zero for the variable indicated and a difference-in-means test between the two groups is therefore not valid. Tests are reported as N/A in the table.{p_end}" |
| noi di as text "" |
|
|
| noi di as text "{col 9}{c TLC}{hline 11}{c TT}{hline 12}{c TT}{hline 37}{c TRC}" |
| noi di as text "{col 9}{c |}{col 13}Test{col 21}{c |}{col 25}Group{col 34}{c |}{col 39}Balance Variable{col 72}{c |}" |
| noi di as text "{col 9}{c LT}{hline 11}{c +}{hline 12}{c +}{hline 37}{c RT}" |
|
|
| forvalues warn_num = 1/`warn_means_num' { |
| noi di as text "{col 9}{c |}{col 11}`warn_means_name`warn_num''{col 21}{c |}{col 23}`warn_means_group`warn_num''{col 34}{c |}{col 37}`warn_means_bvar`warn_num''{col 72}{c |}" |
| } |
| noi di as text "{col 9}{c BLC}{hline 11}{c BT}{hline 12}{c BT}{hline 37}{c BRC}" |
| noi di as text "" |
| } |
|
|
| if `warn_ftest_num' > 0 { |
|
|
| noi di as text "{pmore}{bf:F-Test for Joint Orthogonality:} The variance all groups is zero for the variable indicated and a test of joint orthogonality for all groups is therefore not valid. Tests are reported as N/A in the table.{p_end}" |
| noi di as text "" |
|
|
| noi di as text "{col 9}{c TLC}{hline 25}{c TRC}" |
| noi di as text "{col 9}{c |}{col 13} Balance Variable{col 35}{c |}" |
| noi di as text "{col 9}{c LT}{hline 25}{c RT}" |
|
|
| forvalues warn_num = 1/`warn_ftest_num' { |
| noi di as text "{col 9}{c |}{col 12}`warn_ftest_bvar`warn_num''{col 35}{c |}" |
| } |
| noi di as text "{col 9}{c BLC}{hline 25}{c BRC}" |
| noi di as text "" |
| } |
|
|
| if `anywarning_F' > 0 { |
| noi di as text "{pmore}{bf:Joint Significance Tests:} F-tests are not possible to perform or unreliable. See below for details:{p_end}" |
| noi di as text "" |
|
|
| if `warn_joint_novar_num' > 0 { |
|
|
| noi di as text "{pmore}In the following tests, F-tests were not valid as all variables were omitted in the joint significance test due to collinearity. Tests are reported as N/A in the table.{p_end}" |
| noi di as text "" |
|
|
| noi di as text "{col 9}{c TLC}{hline 12}{c TRC}" |
| noi di as text "{col 9}{c |}{col 13}Test{col 22}{c |}" |
| noi di as text "{col 9}{c LT}{hline 12}{c RT}" |
|
|
| forvalues warn_num = 1/`warn_joint_novar_num' { |
| noi di as text "{col 9}{c |}{col 12}`warn_joint_novar`warn_num''{col 22}{c |}" |
| } |
| noi di as text "{col 9}{c BLC}{hline 12}{c BRC}" |
| noi di as text "" |
| } |
| if `warn_joint_lovar_num' > 0 { |
|
|
| noi di as text "{pmore}In the following tests, F-tests are not valid as the variation in, and the covariation between, the balance variables is too close to zero in the joint test. This could be due to many reasons, but is usually due to a balance variable with high correlation with group dummy. Tests are reported as N/A in the table.{p_end}" |
| noi di as text "" |
|
|
| noi di as text "{col 9}{c TLC}{hline 12}{c TRC}" |
| noi di as text "{col 9}{c |}{col 13}Test{col 22}{c |}" |
| noi di as text "{col 9}{c LT}{hline 12}{c RT}" |
|
|
| forvalues warn_num = 1/`warn_joint_lovar_num' { |
| noi di as text "{col 9}{c |}{col 12}`warn_joint_lovar`warn_num''{col 22}{c |}" |
| } |
| noi di as text "{col 9}{c BLC}{hline 12}{c BRC}" |
| noi di as text "" |
| } |
| if `warn_joint_robus_num' > 0 { |
|
|
| noi di as text "{pmore}In the following tests, F-tests are possible to calculate, but Stata issued a warning. Read more about this warning {help j_robustsingular:here}. Tests are reported with F-values and significance stars (if applicable), but these results might be unreliable.{p_end}" |
| noi di as text "" |
|
|
| noi di as text "{col 9}{c TLC}{hline 12}{c TRC}" |
| noi di as text "{col 9}{c |}{col 13}Test{col 22}{c |}" |
| noi di as text "{col 9}{c LT}{hline 12}{c RT}" |
|
|
| forvalues warn_num = 1/`warn_joint_robus_num' { |
| noi di as text "{col 9}{c |}{col 12}`warn_joint_robus`warn_num''{col 22}{c |}" |
| } |
| noi di as text "{col 9}{c BLC}{hline 12}{c BRC}" |
| noi di as text "" |
| } |
| } |
|
|
| noi di as error "{pstd}Stata issued one or more warnings in relation to the tests in this balance table. Read the warning(s) above carefully before using the values generated for this table.{p_end}" |
| noi di as error "{hline}" |
| noi di as text "" |
|
|
| } |
|
|
| |
| |
|
|
| |
|
|
| |
| |
|
|
| |
| if `COVARIATES_USED' == 1 { |
| local covars_comma = "" |
|
|
| |
| foreach covar of local covariates { |
| if "`covars_comma'" == "" { |
| local covars_comma "and `covar'" |
| local one_covar 1 |
| } |
| else { |
| local covars_comma "`covar', `covars_comma'" |
| local one_covar 0 |
| } |
| } |
|
|
| |
| if `one_covar' == 1 { |
| local covars_comma = subinstr("`covars_comma'" , "and ", "", .) |
| local covar_note "The covariate variable `covars_comma' is included in all estimation regressions. " |
| } |
| else { |
| local covar_note "The covariate variables `covars_comma' are included in all estimation regressions. " |
| } |
| } |
|
|
| |
| local fixed_note "Fixed effects using variable `fixedeffect' are included in all estimation regressions. " |
| local stars_note "***, **, and * indicate significance at the `p3star_percent', `p2star_percent', and `p1star_percent' percent critical level. " |
|
|
| if `PTTEST_USED' == 1 { |
| local ttest_note "The value displayed for t-tests are p-values. " |
| } |
| else { |
| local ttest_note "The value displayed for t-tests are the differences in the means across the groups. " |
| } |
|
|
| if `PFTEST_USED' == 1 { |
| local ftest_note "The value displayed for F-tests are p-values. " |
| } |
| else { |
| local ftest_note "The value displayed for F-tests are the F-statistics. " |
| } |
|
|
| if `VCE_USED' == 1 { |
|
|
| |
| if `STDEV_USED' == 0 { |
| |
| local variance_type_name "Standard errors" |
| } |
| else { |
| |
| local variance_type_name "Standard deviations" |
| } |
|
|
| if "`vce_type'" == "robust" local error_est_note "`variance_type_name' are robust. " |
| if "`vce_type'" == "cluster" local error_est_note "`variance_type_name' are clustered at variable `cluster_var'. " |
| if "`vce_type'" == "bootstrap" local error_est_note "`variance_type_name' are estimeated using bootstrap. " |
| } |
|
|
| if `WEIGHT_USED' == 1 { |
|
|
| local f_weights "fweights fw freq weight" |
| local a_weights "aweights aw" |
| local p_weights "pweights pw" |
| local i_weights "iweights iw" |
|
|
| if `:list weight_type in f_weights' local weight_type = "frequency" |
| else if `:list weight_type in a_weights' local weight_type = "analytical" |
| else if `:list weight_type in p_weights' local weight_type = "probability" |
| else if `:list weight_type in i_weights' local weight_type = "importance" |
|
|
| local weight_note "Observations are weighted using variable `weight_var' as `weight_type' weights." |
|
|
| } |
|
|
|
|
| if `BALMISS_USED' == 1 | `BALMISSREG_USED' == 1 { |
|
|
| if `BALMISS_USED' == 1 local balmiss_note "All missing values in balance variables are treated as zero." |
| if `BALMISSREG_USED' == 1 local balmiss_note "Regular missing values in balance variables are treated as zero, {help missing:extended missing values} are still treated as missing." |
|
|
| local BALMISS_USED = 1 |
| } |
|
|
|
|
|
|
| if `COVMISS_USED' == 1 | `COVMISSREG_USED' == 1 { |
|
|
| if `COVMISS_USED' == 1 local covmiss_note "All missing values in covariate variables are treated as zero." |
| if `COVMISSREG_USED' == 1 local covmiss_note "Regular missing values in covariate variables are treated as zero, {help missing:extended missing values} are still treated as missing." |
|
|
| local COVMISS_USED = 1 |
| } |
|
|
|
|
| |
|
|
| if `NOTECOMBINE_USED' == 1 { |
|
|
| |
|
|
| |
| if `FTEST_USED' == 0 local ftest_note "" |
| if `VCE_USED' == 0 local error_est_note "" |
| if `WEIGHT_USED' == 0 local weight_note "" |
| if `FIX_EFFECT_USED' == 0 local fixed_note "" |
| if `COVARIATES_USED' == 0 local covar_note "" |
| if `BALMISS_USED' == 0 local balmiss_note "" |
| if `COVMISS_USED' == 0 local covmiss_note "" |
| if `STARSNOADD_USED' == 1 local stars_note "" |
|
|
|
|
| |
| file open `textname' using "`textfile'", text write append |
|
|
| file write `textname' "`tblnote' `ttest_note'`ftest_note'`error_est_note'`fixed_note'`covar_note'`weight_note'`balmiss_note'`covmiss_note'`stars_note'" _n |
|
|
| file close `textname' |
|
|
|
|
| } |
| else if `NONOTE_USED' == 1 { |
|
|
| |
|
|
| file open `textname' using "`textfile'", text write append |
|
|
| if `NOTE_USED' file write `textname' "`tblnote'" _n |
|
|
| file close `textname' |
|
|
| } |
| else { |
|
|
| file open `textname' using "`textfile'", text write append |
|
|
| if `NOTE_USED' file write `textname' "`tblnote'" _n |
| file write `textname' "`ttest_note'" _n |
| if `FTEST_USED' file write `textname' "`ftest_note'" _n |
| if `VCE_USED' file write `textname' "`error_est_note'" _n |
| if `FIX_EFFECT_USED' file write `textname' "`fixed_note'" _n |
| if `COVARIATES_USED' file write `textname' "`covar_note'" _n |
| if `BALMISS_USED' file write `textname' "`balmiss_note'" _n |
| if `COVMISS_USED' file write `textname' "`covmiss_note'" _n |
| if !`STARSNOADD_USED' file write `textname' "`stars_note'" _n |
| file close `textname' |
|
|
| } |
|
|
| |
|
|
| |
| |
| if `FTEST_USED' == 0 local ftest_note "" |
| if `VCE_USED' == 0 local error_est_note "" |
| if `WEIGHT_USED' == 0 local weight_note "" |
| if `FIX_EFFECT_USED' == 0 local fixed_note "" |
| if `COVARIATES_USED' == 0 local covar_note "" |
| if `BALMISS_USED' == 0 local balmiss_note "" |
| if `COVMISS_USED' == 0 local covmiss_note "" |
| if `STARSNOADD_USED' == 1 local stars_note "" |
|
|
| |
| local notes_list "tblnote error_est_note weight_note fixed_note covar_note" |
|
|
| foreach note of local notes_list { |
|
|
| local `note' : subinstr local `note' "_" "\_" , all |
| local `note' : subinstr local `note' "%" "\%" , all |
| local `note' : subinstr local `note' "&" "\&" , all |
| local `note' : subinstr local `note' "\$" "\\\$" , all |
|
|
| } |
|
|
| |
| if `TEXCOLWIDTH_USED' == 0 local totalColNo = strlen("`colstring'") |
| else { |
| local colstrBracePos = strpos("`colstring'","}") |
| local nonLabelCols = substr("`colstring'",`colstrBracePos'+1,.) |
| local totalColNo = strlen("`nonLabelCols'") +1 |
| } |
|
|
| |
| |
| if `NOTEWIDTH_USED' == 0 local texnotewidth = 1 |
|
|
| file open `texname' using "`texfile'", text write append |
|
|
| file write `texname' |
| "\hline \hline \\[-1.8ex]" _n |
|
|
| |
| |
| if `NONOTE_USED' & `NOTE_USED' { |
| file write `texname' |
| "%%% This is the note. If it does not have the correct margins, use texnotewidth() option or change the number before '\textwidth' in line below to fit it to table size." _n |
| "\multicolumn{`totalColNo'}{@{} p{`texnotewidth'\textwidth}}" _n |
| `"{\textit{Notes}: `tblnote'}"' _n |
| } |
|
|
| else if ! `NONOTE_USED' { |
|
|
| |
| file write `texname' |
| "%%% This is the note. If it does not have the correct margins, edit text below to fit to table size." _n |
| "\multicolumn{`totalColNo'}{@{}p{`texnotewidth'\textwidth}}" _n |
| `"{\textit{Notes}: `tblnote' `ttest_note'`ftest_note'`error_est_note'`fixed_note'`covar_note'`weight_note'`balmiss_note'`covmiss_note'`stars_note'}"' _n |
| } |
|
|
| file write `texname' |
| "\end{tabular}" _n |
| file close `texname' |
|
|
|
|
| if `TEXDOC_USED' { |
|
|
| file open `texname' using "`texfile'", text write append |
| file write `texname' |
| "\end{adjustbox}" _n |
| "\end{table}" _n |
| "\end{document}" _n |
|
|
| file close `texname' |
| } |
|
|
|
|
| |
| |
|
|
| |
|
|
| |
| |
|
|
| |
| restore |
|
|
|
|
|
|
|
|
| if !( `BROWSE_USED' | `SAVE_BROWSE_USED' ) preserve |
|
|
|
|
| |
| |
|
|
| |
| if c(version) < 13 { |
|
|
| |
| insheet using "`textfile'", tab clear |
| } |
| else { |
|
|
| |
| import delimited using "`textfile'", clear delimiters("\t") |
| } |
|
|
| |
| |
|
|
| |
| if `SAVE_USED' { |
|
|
| export excel using `"`save'"', `replace' |
|
|
| noi di as result `"{phang}Balance table saved to: {browse "`save'":`save'} "' |
| } |
|
|
| |
| if `SAVE_TEX_USED' { |
|
|
| copy "`texfile'" `"`savetex'"', `replace' |
|
|
| noi di as result `"{phang}Balance table saved to: {browse "`savetex'":`savetex'} "' |
| } |
|
|
|
|
| if !( `BROWSE_USED' | `SAVE_BROWSE_USED' ) restore |
|
|
|
|
| } |
|
|
| end |
|
|
| |
| |
| |
| cap program drop iereplacestringtest |
| program define iereplacestringtest |
|
|
| args optionname replacetypestring |
|
|
| if !("`replacetypestring'" == "zero" | "`replacetypestring'" == "mean" | "`replacetypestring'" == "groupmean") { |
|
|
| noi display as error "{phang}The string entered in option `optionname'(`replacetypestring') is not a valid replace type string. Only zero, mean and groupmean is allowed. See {help iebaltab:help iebaltab} for more details.{p_end}" |
| error 198 |
| } |
|
|
| end |
|
|
| |
| |
| cap program drop iereplacemiss |
| program define iereplacemiss |
|
|
| syntax varname, replacetype(string) [minobsmean(numlist) regonly groupvar(varname) groupcodes(string)] |
|
|
| |
| if "`regonly'" == "" { |
| local misstype "`varlist' >= ." |
| } |
| else { |
| local misstype "`varlist' == ." |
| } |
|
|
|
|
| |
| |
| if "`minobsmean'" == "" { |
| local minobs 10 |
| } |
| else { |
| |
| local minobs `minobsmean' |
| } |
|
|
|
|
| |
| |
| if "`replacetype'" == "zero" { |
|
|
| |
| replace `varlist' = 0 if `misstype' |
|
|
| } |
| else if "`replacetype'" == "mean" { |
|
|
| |
| sum `varlist' |
|
|
| |
| if `r(N)' < `minobs' { |
| noi display as error "{phang}Not enough observations. There are less than `minobs' observations with a nonmissing value in `varlist'. Missing values can therefore not be set to the mean. Click {stata tab `varlist', missing} for detailed information.{p_end}" |
| error 2001 |
| } |
|
|
| |
| replace `varlist' = `r(mean)' if `misstype' |
|
|
| } |
| else if "`replacetype'" == "groupmean" { |
|
|
| |
| foreach code of local groupcodes { |
|
|
| |
| sum `varlist' if `groupvar' == `code' |
|
|
| |
| if `r(N)' == 0 { |
|
|
| noi display as error "{phang}No observations. All values are missing in variable `varlist' for group `code' in variable `groupvar' and missing values can therefore not be set to the group mean. Click {stata tab `varlist' if `groupvar' == `code', missing} for detailed information.{p_end}" |
| error 2000 |
| } |
| if `r(N)' < `minobs' { |
|
|
| noi display as error "{phang}Not enough observations. There are less than `minobs' observations in group `code' in variable `groupvar' with a non missing value in `varlist'. Missing values can therefore not be set to the group mean. Click {stata tab `varlist' if `groupvar' == `code', missing} for detailed information.{p_end}" |
| error 2001 |
|
|
| } |
|
|
| |
| replace `varlist' = `r(mean)' if `misstype' & `groupvar' == `code' |
| } |
|
|
| } |
|
|
| end |
|
|
|
|
| cap program drop iecontrolheader |
| program define iecontrolheader, rclass |
|
|
| args control ORDER_OF_GROUPS GRPVAR_NUM_GROUPS TTEST_USED PTTEST_USED NORMDIFF_USED titlerow1 titlerow2 titlerow3 texrow3 |
|
|
| local ttest_pairs "" |
|
|
| |
| |
| local ctrlGrpPos : list posof "`control'" in ORDER_OF_GROUPS |
|
|
| |
| forvalues second_ttest_group = 1/`GRPVAR_NUM_GROUPS' { |
| if `second_ttest_group' != `ctrlGrpPos' { |
| local ttest_pairs "`ttest_pairs' `ctrlGrpPos'_`second_ttest_group'" |
| } |
| } |
|
|
| if `TTEST_USED' { |
|
|
| forvalues second_ttest_group = 1/`GRPVAR_NUM_GROUPS' { |
|
|
| |
| if `second_ttest_group' != `ctrlGrpPos' { |
|
|
| |
| local titlerow1 `"`titlerow1' _tab "t-test""' |
| if `PTTEST_USED' local titlerow2 `"`titlerow2' _tab "p-value""' |
| else local titlerow2 `"`titlerow2' _tab "Difference""' |
| local titlerow3 `"`titlerow3' _tab "(`ctrlGrpPos')-(`second_ttest_group')""' |
|
|
| local texrow3 `" `texrow3' & (`ctrlGrpPos')-(`second_ttest_group') "' |
|
|
| } |
| } |
| } |
|
|
| if `NORMDIFF_USED' { |
|
|
| forvalues second_ttest_group = 1/`GRPVAR_NUM_GROUPS' { |
|
|
| |
| if `second_ttest_group' != `ctrlGrpPos' { |
|
|
| local titlerow1 `"`titlerow1' _tab "Normalized""' |
| local titlerow2 `"`titlerow2' _tab "difference""' |
| local titlerow3 `"`titlerow3' _tab "(`ctrlGrpPos')-(`second_ttest_group')""' |
|
|
| local texrow3 `" `texrow3' & (`ctrlGrpPos')-(`second_ttest_group') "' |
| } |
| } |
| } |
|
|
| return local titlerow1 `"`titlerow1'"' |
| return local titlerow2 `"`titlerow2'"' |
| return local titlerow3 `"`titlerow3'"' |
|
|
| return local texrow3 `"`texrow3'"' |
|
|
| return local ttest_pairs `"`ttest_pairs'"' |
|
|
| end |
|
|
| cap program drop ienocontrolheader |
| program define ienocontrolheader, rclass |
|
|
| args GRPVAR_NUM_GROUPS TTEST_USED PTTEST_USED NORMDIFF_USED titlerow1 titlerow2 titlerow3 texrow3 |
|
|
| local ttest_pairs "" |
|
|
| |
| forvalues first_ttest_group = 1/`GRPVAR_NUM_GROUPS' { |
|
|
| |
| |
| |
| local nextPossGroup = `first_ttest_group' + 1 |
|
|
| |
| forvalues second_ttest_group = `nextPossGroup'/`GRPVAR_NUM_GROUPS' { |
| local ttest_pairs "`ttest_pairs' `first_ttest_group'_`second_ttest_group'" |
| } |
| } |
|
|
| |
| if `TTEST_USED' { |
| forvalues first_ttest_group = 1/`GRPVAR_NUM_GROUPS' { |
|
|
| |
| |
| |
| local nextPossGroup = `first_ttest_group' + 1 |
|
|
| forvalues second_ttest_group = `nextPossGroup'/`GRPVAR_NUM_GROUPS' { |
|
|
| local titlerow1 `"`titlerow1' _tab "t-test""' |
| if `PTTEST_USED' local titlerow2 `"`titlerow2' _tab "p-value""' |
| else local titlerow2 `"`titlerow2' _tab "Difference""' |
| local titlerow3 `"`titlerow3' _tab "(`first_ttest_group')-(`second_ttest_group')""' |
|
|
| local texrow3 `" `texrow3' & (`first_ttest_group')-(`second_ttest_group') "' |
| } |
| } |
| } |
|
|
| |
| if `NORMDIFF_USED' { |
| forvalues first_ttest_group = 1/`GRPVAR_NUM_GROUPS' { |
|
|
| |
| |
| |
| local nextPossGroup = `first_ttest_group' + 1 |
|
|
| forvalues second_ttest_group = `nextPossGroup'/`GRPVAR_NUM_GROUPS' { |
|
|
| local titlerow1 `"`titlerow1' _tab "Normalized""' |
| local titlerow2 `"`titlerow2' _tab "difference""' |
| local titlerow3 `"`titlerow3' _tab "(`first_ttest_group')-(`second_ttest_group')""' |
|
|
| local texrow3 `" `texrow3' & (`first_ttest_group')-(`second_ttest_group') "' |
| } |
| } |
| } |
|
|
| return local titlerow1 `"`titlerow1'"' |
| return local titlerow2 `"`titlerow2'"' |
| return local titlerow3 `"`titlerow3'"' |
|
|
| return local texrow3 `"`texrow3'"' |
|
|
| return local ttest_pairs `"`ttest_pairs'"' |
|
|
| end |
|
|