Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: how can I save confidence intervals, t and p values in macros?

From   Joseph Coveney <>
To   Statalist <>
Subject   Re: st: how can I save confidence intervals, t and p values in macros?
Date   Thu, 13 Jul 2006 14:24:03 +0900

Maarten Buis wrote:

> ---Tim Asked:
> i have checked the manuals and searched the help. e(b) gives the
> coefficient estimates, and e(V) gives the covariance of the
> estimates. But do I then have to calculate the p, the t, and the
> Confidence Intervals by hand?

--- Michael Blasnik answered:
> Otherwise, you will have to do it "by hand", which can
> be automated fairly easily depending on your ultimate goal.

Examples of automating these calculations can be found in earlier post
on the statalist, e.g.


As Michael and Maarten mention, the task is fairly straightforward and has
come up on the list before.

If Tim is just putting the Wald t, p and CLs for each of the predictors and
intercept of a single-equation linear model into a series of local or global
macros, then it's scarcely more than a half-dozen lines of code for the
whole kit and caboodle.

Joseph Coveney

set more off
sysuse auto, clear
regress headroom trunk weight length turn
* Begin here
local predictor_list : colnames e(b) // Watch for dropped variables
foreach predictor of local predictor_list {
    local t_`predictor' = _b[`predictor'] / _se[`predictor']
    local p_`predictor' = 2 * ttail(e(df_r), abs(`t_`predictor''))
    local half_alpha = (1 - `c(level)' / 100) / 2
    local lcl_`predictor' = _b[`predictor'] + ///
      invttail(e(df_r), 1-`half_alpha') * _se[`predictor']
    local ucl_`predictor' = _b[`predictor'] + ///
      invttail(e(df_r), `half_alpha') * _se[`predictor']
* Done
macro list

*   For searches and help try:

© Copyright 1996–2021 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index