Statalist The Stata Listserver


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

st: How to compute t-stats and p-values with bootstrap following qreg in stata9


From   [email protected]
To   [email protected]
Subject   st: How to compute t-stats and p-values with bootstrap following qreg in stata9
Date   Sat, 26 May 2007 19:18:15 +0800

Dear Stata 9 experts,

I was using the following lines of command by Brian Poi to routinely
compute t-stats and p-values after qreg. I adapted the bootstrap code to
stata 9, but got an error message. Is something wrong with the syntax or is
stata 9 to be handled differently?

Bonus Question: Is there a simpler way of obtaining t-stats and p-values in
stata 9?

many thanks!

Patrick.
[email protected]

The original code by Brian Poi (See
http://www.stata.com/statalist/archive/2004-04/msg00153.html):

        sysuse auto, clear
        set seed 1001
        bootstrap "qreg price weight length foreign" _b, reps(1000)
        // The following code should work after any call to
        // -bootstrap-
        matrix b = e(b)
        matrix se = e(se)
        local names : colnames(se)
        local df = e(N) - colsof(b)
        tempname t lb ub
        local i = 1
        foreach var of local names {
                scalar `t' = (b[1, `i'] / se[1, `i'])
                scalar `lb' = b[1, `i'] - se[1, `i']*invttail(`df', 0.025)
                scalar `ub' = b[1, `i'] + se[1, `i']*invttail(`df', 0.025)
                di "`var'" _col(15) %9.0g b[1,`i'] ///
                           _col(26) %9.0g se[1, `i'] ///
                           _col(38) %6.2f `t' ///
                           _col(46) %6.3f 2*ttail(`df', abs(`t')) ///
                           _col(56) %9.0g `lb' ///
                           _col(68) %9.0g `ub'
                local i = `i' + 1
        }

The code adapted to stata 9:

        sysuse auto, clear
        set seed 1001
        bootstrap _b, reps(1000) seed(1001) : qreg price weight length
foreign
        // The following code should work after any call to
        // -bootstrap-
        matrix b = e(b)
        matrix se = e(se)
        local names : colnames(se)
        local df = e(N) - colsof(b)
        tempname t lb ub
        local i = 1
        foreach var of local names {
                scalar `t' = (b[1, `i'] / se[1, `i'])
                scalar `lb' = b[1, `i'] - se[1, `i']*invttail(`df', 0.025)
                scalar `ub' = b[1, `i'] + se[1, `i']*invttail(`df', 0.025)
                di "`var'" _col(15) %9.0g b[1,`i'] ///
                           _col(26) %9.0g se[1, `i'] ///
                           _col(38) %6.2f `t' ///
                           _col(46) %6.3f 2*ttail(`df', abs(`t')) ///
                           _col(56) %9.0g `lb' ///
                           _col(68) %9.0g `ub'
                local i = `i' + 1
        }

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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