I would like to construct confidence intervals by test inversion. My first hunch was to use the Stata command permute and run it for a wide range of null hypotheses, and based on this determine the appropriate confidence interval. I do not know, however, how to properly test for an alternative hypothesis using permute. The basic code is this:
Which prints:
Now, I wish to run something similar for other hypotheses, e.g. not only that _b[safewater] = .238561, to be able to construct a confidence interval for the point estimate.
My first thought was to do something like this:
However, even for extreme values, it just reports exactly the same values for the permutation test, making me doubt whether this is a correct approach.
Any suggestions on how to do this using permute or any other Stata command would be appreciated!
Code:
webuse lifeexp permute safewater _b, reps(1000): reg lexp safewater, r
Code:
Monte Carlo permutation results Number of observations = 40 Permutation variable: safewater Number of permutations = 1,000 Command: regress lexp safewater, r _pm_1: _b[safewater] ------------------------------------------------------------------------------- | Monte Carlo error | ------------------- T | T(obs) Test c n p SE(p) [95% CI(p)] -------------+----------------------------------------------------------------- _pm_1 | .238561 lower 1000 1000 1.0000 .0000 .9963 1.0000 | upper 0 1000 .0000 .0000 .0000 .0037 | two-sided .0000 .0000 . . ------------------------------------------------------------------------------- Notes: For lower one-sided test, c = #{T <= T(obs)} and p = p_lower = c/n. For upper one-sided test, c = #{T >= T(obs)} and p = p_upper = c/n. For two-sided test, p = 2*min(p_lower, p_upper); SE and CI approximate.
Now, I wish to run something similar for other hypotheses, e.g. not only that _b[safewater] = .238561, to be able to construct a confidence interval for the point estimate.
My first thought was to do something like this:
Code:
permute safewater (_b[safewater]-0.2), reps(1000): reg lexp safewater, r
Code:
Monte Carlo permutation results Number of observations = 40 Permutation variable: safewater Number of permutations = 1,000 Command: regress lexp safewater, r _pm_1: _b[safewater]-0.2 ------------------------------------------------------------------------------- | Monte Carlo error | ------------------- T | T(obs) Test c n p SE(p) [95% CI(p)] -------------+----------------------------------------------------------------- _pm_1 | .038561 lower 1000 1000 1.0000 .0000 .9963 1.0000 | upper 0 1000 .0000 .0000 .0000 .0037 | two-sided .0000 .0000 . . ------------------------------------------------------------------------------- Notes: For lower one-sided test, c = #{T <= T(obs)} and p = p_lower = c/n. For upper one-sided test, c = #{T >= T(obs)} and p = p_upper = c/n. For two-sided test, p = 2*min(p_lower, p_upper); SE and CI approximate.
Comment