Skip to content

Commit

Permalink
iebaltab : missing values documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
kbjarkefur committed Sep 8, 2022
1 parent ff700aa commit 2e1d71c
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 28 deletions.
66 changes: 38 additions & 28 deletions src/ado_files/iebaltab.ado
Original file line number Diff line number Diff line change
Expand Up @@ -779,9 +779,9 @@ qui {
mat row[1,`++colindex'] = `sd'
}
else {
*If total not specified, then put .m in all total columns
*If total not specified, then put .t in all total columns
foreach tot_stat of local desc_stats {
mat row[1,`++colindex'] = .m
mat row[1,`++colindex'] = .t
}
}

Expand All @@ -791,7 +791,8 @@ qui {
foreach ttest_pair of local TEST_PAIR_CODES {

*If none is used then no pair test stats are calculated
if "`pout_val'" == "none" {
get_stat_label_stats_string, stats_string("`stats_string'") testname("pair")
if "`r(stat_label)'" == "none" {
foreach tot_stat of local pair_stats {
mat row[1,`++colindex'] = .m
}
Expand All @@ -809,14 +810,17 @@ qui {
//noi di "Balance regression. Var [`balancevar'], test pair [`ttest_pair']"
reg `balancevar' `dummy_pair_`ttest_pair'' `covariates' i.`fixedeffect' `weight_option', `error_estm'

* R2 = 100
if (e(r2) == 1) noi display as text "{phang}Warning: All variance was explained by one variable in the regression for the pair-wise test of variable [`balancevar'] for observations with values [`code1'] and [`code2'] in the groupvar [`grpvar'].{p_end}."

* R2 = 0
if (e(r2) == .) noi display as text "{phang}Warning: The R2 was not possible to calculate in the regression for the pair-wise test of variable [`balancevar'] for observations with values [`code1'] and [`code2'] in the groupvar [`grpvar'].{p_end}."

*If any of the tests
if (e(r2) == .) | (e(r2) == 1) {
if (e(r2) == .) {
* R2 is undefined
noi display as text "{phang}Warning: The R2 was not possible to calculate in the regression for the pair-wise test of variable [`balancevar'] for observations with values [`code1'] and [`code2'] in the groupvar [`grpvar'].{p_end}."
foreach stat of local pair_stats {
mat row[1,`++colindex'] = .n
}
}
else if (e(r2) == 1) {
* R2 = 100
noi display as text "{phang}Warning: All variance was explained by one or several variables in the regression for the pair-wise test of variable [`balancevar'] for observations with values [`code1'] and [`code2'] in the groupvar [`grpvar'].{p_end}."
foreach stat of local pair_stats {
mat row[1,`++colindex'] = .v
}
Expand Down Expand Up @@ -881,14 +885,17 @@ qui {
//noi di "FEQ regression. Var [`balancevar']"
reg `balancevar' i.`grpvar' `covariates' i.`fixedeffect' `weight_option', `error_estm'

* R2 = 100
if (e(r2) == 1) noi display as text "{phang}Warning: All variance was explained by one variable in the regression for the feq-test over all values in the group variable [`grpvar'] for balance variable [`balancevar'].{p_end}."

* R2 = 0
if (e(r2) == .) noi display as text "{phang}Warning: The R2 value could not be calculated in the regression for the feq-test over all values in the group variable [`grpvar'] for balance variable [`balancevar'].{p_end}
*If any of the tests
if (e(r2) == .) | (e(r2) == 1) {
if (e(r2) == .) {
* R2 undefined
noi display as text "{phang}Warning: The R2 value could not be calculated in the regression for the feq-test over all values in the group variable [`grpvar'] for balance variable [`balancevar'].{p_end}"
foreach stat of local feq_stats {
mat row[1,`++colindex'] = .n
}
}
else if (e(r2) == 1) {
* R2 = 1
noi display as text "{phang}Warning: All variance was explained by one or several variables in the regression for the feq-test over all values in the group variable [`grpvar'] for balance variable [`balancevar'].{p_end}"
foreach stat of local feq_stats {
mat row[1,`++colindex'] = .v
}
Expand All @@ -907,10 +914,10 @@ qui {

}
}
* Feq test not used - save missing .m
* Feq test not used - save missing .f
else {
foreach feq_stat of local feq_stats {
mat row[1,`++colindex'] = .m
mat row[1,`++colindex'] = .f
}
}

Expand Down Expand Up @@ -950,13 +957,16 @@ qui {
* Find ommitted balance vars if any
local all_columns : colnames r(table)
local omitted_balvars : list balancevars - all_columns
if !missing("`omitted_balvars'") noi display as text "{phang}Warning: One or more balance variables were omitted due to no variance in the F-test across all balance variables for group variable values `code1' and `code2'.{p_end}."
* All variation in group var is explained by a balance variable
if e(r2) == 1 noi display as text "{phang}Warning: All variance in the F-test across all balance variables for group variable values `code1' and `code2' is explained by one or more independent variables.{p_end}."
* If not possible to calculate F-test due to variance issues,
if !missing("`omitted_balvars'") | e(r2) == 1 {
if !missing("`omitted_balvars'") {
noi display as text "{phang}Warning: One or more balance variables were omitted due to no variance in the F-test across all balance variables for group variable values `code1' and `code2'.{p_end}."
foreach f_stat of local ftest_stats {
mat `fmat'[1,`++Fcolindex'] = .o
}
}
else if (e(r2) == 1) {
* R2 = 1
noi display as text "{phang}Warning: All variance in the F-test across all balance variables for group variable values `code1' and `code2' is explained by one or more independent variables.{p_end}."
foreach f_stat of local ftest_stats {
mat `fmat'[1,`++Fcolindex'] = .v
}
Expand All @@ -979,10 +989,10 @@ qui {
}
}
else {
* F test not used, mark all f-test values as .m
* F test not used, mark all f-test values as .f
foreach ftest_pair of local TEST_PAIR_CODES {
foreach f_stat of local ftest_stats {
mat `fmat'[1,`++Fcolindex'] = .m
mat `fmat'[1,`++Fcolindex'] = .f
}
}
}
Expand Down Expand Up @@ -2513,7 +2523,7 @@ cap program drop generate_note
vce_type(string) clustervar(string) ///
weight_type(string) weight_var(string) ]
local table_note ""
local table_note "If the table includes missing values (.n, .o, .v etc.) see the Missing values section in the help file for the Stata command iebaltab for definitions of these values. "
* Get stats and label for pairs and f-test
get_stat_label_stats_string, stats_string("`stats_string'") testname("pair")
Expand Down
91 changes: 91 additions & 0 deletions src/help_files/iebaltab.sthlp
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,97 @@ in the {it:Estimation/statistics definitions} section above.{p_end}

{pstd}See examples below for how to access the values.{p_end}

{title:Missing values}

{pstd}When statistics are estimated/calculated they can be missing for multiple reasons.
This section explain what each
{help missing:extended missing values} ({inp:.c},{inp:.v} etc.) represents.
The exported tables or the result matrices should never include
the standard missing value ({inp:.}).
If you ever encounter the standard missing value in any of them,
please report that using the contact information at the bottom of this help file.{p_end}

{pstd}{ul:{it:Missing value: .b}}{break}
Missing value {inp:.b} means that the statistics
could not be estimated/calculated as bootstrapping was set
to be used as the variance estimator in {inp:vce(bootstrap)}.
When bootstrap is used there is no single value for variance
to be reported in stat {inp:desc(var)}.
As a result of that, the stats {inp:pair(nrmd)} and {inp:pair(nrmb)}
are not reported either as they use the variance as input.{p_end}

{pstd}{ul:{it:Missing value: .c}}{break}
Missing value {inp:.c} are only used when there is
no number of clusters to report as the errors estimations were not cluster.
A value for number of clusters are only reported if the
variance estimator option is set to {inp:vce(cluster {it:clustervar})}.{p_end}

{pstd}{ul:{it:Missing value: .f}}{break}
Missing value {inp:.f} is used to indicate that f-test option for
that statistics (either {inp:fstat} or {inp:feqstat}) was not used,
and the value was therefore not calculated.{p_end}

{pstd}{ul:{it:Missing value: .m}}{break}
Missing value {inp:.m} is used to indicate that an option to skip
a full section was used. For example, {inp:stats(pair(none))} where all
pair-wise statistics are skipped.{p_end}

{pstd}{ul:{it:Missing value: .n}}{break}
Missing value {inp:.n} is used to indicate that the R-squared value
was not defined in the pair-wise regression for this test pair.
This is most likely caused by no variance in the balance variable.
Here is an example:{p_end}

{pstd}{inp:sysuse census}{break}
{inp:gen constant = 1}{break}
{inp:iebaltab medage constant, grpvar(region) browse}{p_end}

{pstd}In this example the variable {inp:constant} has no variance.
This variable has the mean 1 and 0 variance in the descriptive statistics
and statistics can be reported in the descriptive statistics section.
However, the R-square value is not defined for any test pair
in the pair-wise regression,
and no pair-wise stats are reported for the {inp:constant} variable.{p_end}

{pstd}{ul:{it:Missing value: .o}}{break}
Missing value {inp:.o} is used to indicate that in the F-test regression
for joint significance across all balance variables (see option {inp:ftest})
for this test pair and at least one balance variable was omitted.
This is most likely caused by no variance in that balance variable.
Here is an example:{p_end}

{pstd}{inp:sysuse census}{break}
{inp:replace pop = 0 if (region == 1) | (region == 2)}{break}
{inp:iebaltab medage pop, grpvar(region) ftest browse}{p_end}

{pstd}In this example the variable {inp:pop} has no variance in test pair 1_2,
and that variable will be omitted from the F-test regression and
no stats are reported for this F-test for this test pair.{p_end}

{pstd}{ul:{it:Missing value: .t}}{break}
Missing value {inp:.t} is used to indicate that no descriptive statistics
were calculated for the full sample since the option {inp:total} was not used.{p_end}

{pstd}{ul:{it:Missing value: .v}}{break}
Missing value {inp:.v} is used to indicate that
all variance in the balance variable can be explained by one or several
other variables included in the regression.
This is defined as the R-squared value is 1.
Here are a few examples:{p_end}

{pstd}{inp:sysuse census}{break}
{inp:gen region2 = region}{break}
{inp:gen pop_neg = 0}{break}
{inp:replace pop_neg = pop * -1 if (region == 1) | (region == 2)}{break}
{inp:iebaltab medage pop region2, grpvar(region) covar(pop_neg) browse}{p_end}

{pstd}The variance in variable {inp:region2} is perfectly explained
by the group variable {inp:region} for each test pair
and the R-sqaured is 1 in all pair-wise regressions and no statistics are reported.
Similarly, {inp:pop_neg} that is included as a covariate control variable
has prefect negative correlation with the balance variable {inp:pop} in test pair 1_2.
The R-sqaured is 1 in the regression for pair 1_2 and no pair-wise statistics are reported for that pair.{p_end}

{title:Examples}

{pstd}{hi:Example 1.}
Expand Down

0 comments on commit 2e1d71c

Please sign in to comment.