1
votes

I have written a program in Stata to perform a cluster bootstrap-t procedure for estimating t-statistics and parameter confidence intervals. The goal of the program is to use t-tests and to create CIs that are robust to cluster correlation, even for small numbers of clusters. For the curious, this is built off the "cluster bootstrap-t with asymptotic refinement" procedure described in Cameron, Gelbach, and Miller (2008): "Bootstrap-Based Improvements for Inference with Clustered Errors."

The problem is that I want to create a nice-looking regression table to output for the user, similar to what standard Stata regressions report. However, I cannot use the usual function "ereturn", because my program creates t-statistics and confidence intervals based on bootstrapping the t-statistic. As I understand the "ereturn" function, it requires a vector of parameters and a variance-covariance matrix as input, and then calculates the standard errors, t-statistics, and 95% CIs itself. This means that I cannot simply input my t-statistic p-values and 95% CIs into the "ereturn" function. Even if I calculate bootstrapped standard errors to fill in the variances in a VCV, the t-statistics and CIs would be wrong.

Is there another function in Stata that returns tables to the user and could be used to report the results of my program? Can I change the code of "ereturn" and save it as another program that will accept my statistics to output? Or am I stuck with outputting the results in simple text display?

3

3 Answers

2
votes

Your hypothesis can easily be tested by writing some code. The facetious example here

program whatever, eclass 
    ereturn scalar answer = 42 
end

shows that an e-class program can be created that returns e-class results of one's choosing. It's no more than a common convention (for all that it makes much statistical sense) to return a variance-covariance matrix. That is not an essential part of the syntactic definition.

. whatever

. eret li

scalars:
         e(answer) =  42

Note that ereturn is not a Stata function, but a command. Nor could Stata functions help you out here if matters were otherwise. In Stata, functions and commmands are disjoint. Naturally, terminology is often different elsewhere.

2
votes

To complement @Nick's answer.

It should already be clear that you can write programs, be that e-class or r-class, that give similar results. Taking from his code:

*----- example programs -----

capture program drop whatever
program whatever, eclass 
    ereturn post
    ereturn scalar answer = 42 
end

capture program drop whatever2
program whatever2, rclass 
    return scalar answer = 42 
end

*----- use programs -----

whatever
ereturn list

whatever2
return list

But beware that there are differences between these two types, and they should be clarified reading, at least, [U] 18.10 Saving results. Choose your program type accordingly.

Now another point. You say

The problem is that I want to create a nice-looking regression table to output for the user, similar to what standard Stata regressions report. However, I cannot use the usual function "ereturn",

There's no reason to think the program class will impede such tables:

*----- example programs -----

// first program
capture program drop whatever
program whatever, eclass 
    ereturn post
    local ans = 42
    ereturn scalar answer = `ans' 

    // table
    di as smcl as txt                ///
        _col( 7) "Whatever {c |}"    ///
        _col(22) "Value"              

    di as smcl as txt "  {hline 13}{c +}{hline 62}"

    di as smcl as txt              ///
        _col( 8) "        {c |}"   ///
        _col(23) `ans'     
end

// second program
capture program drop whatever2
program whatever2, rclass 
    local ans = 42
    return scalar answer = `ans' 

    // table
    di as smcl as txt                ///
        _col( 6) "Whatever2 {c |}"   ///
        _col(22) "Value"              

    di as smcl as txt "  {hline 13}{c +}{hline 62}"

    di as smcl as txt              ///
        _col( 8) "        {c |}"   ///
        _col(23) `ans'      
end

*----- use programs -----

whatever
ereturn list

whatever2
return list

If you want a table as a result, you simply use display (or di) within your program definition. There's nothing special in those tables, but they should get the point across.

You can check how StataCorp programmers and other programmers/users display tables taking a look at the .ado files they write. See help viewsource.

0
votes

The method I ended up using to make my regression table output is the "estout" command. "estout" allows for you to display a matrix in a pretty-looking table that is already formatted, with some relatively simple options for changing how it displays. I hope this helps anyone who faces a similar situation.

estout matrix(final, fmt(%10.0g %10.0g %10.0g %12.4f %10.0g %10.0g)), ///
style(smcl) title("Model Results") mlabels("", none) modelwidth(10 10 10 6 10 10)

Using an already-labeled matrix that already contains the vector of coefficients, standard errors, t-values, p-values, and 95% CIs, this command produces a table that looks pretty similar to a standard Stata regression table.