Jun 11

Saved Results in Stata 10

Tag: stataadmin @ 9:58 pm

One of the more interesting feature in Stata 10 is the ability to save estimation results:

Stata 10 allows you to store estimation results in a file for use in later sessions. Fit a model today, save the results to disk, come back tomorrow, load the results, and continue with postestimation analysis as if you never exited Stata. Or email your results file to a colleague for further review. estimates save and estimates use make these tasks easy.

This new feature does not address a problem that continues to push me towards Matlab: the ability to save coefficient estimates, standard errors, r^2, etc in variables. For example, I am working on a modified version of the Heckman sample selection problem where the first stage is an ordered probit. I need to save some of the coefficient estimates for the second stage estimation. Right now, I have to cut and paste the results in the second stage .do file before running it. Annoying…

2 Responses to “Saved Results in Stata 10”

  1. JohnZ says:

    I had a similar problem, but it is possible to save the estimation results as a dataset. Here’s my code to do it (also saves the labels of variables), which should work for any estimator that saves results in e(V) and e(b):

    *!
    *! est2data.ado –
    *!
    *! Usage: est2data nbase outfname
    *!
    *! Saves the ‘b’ and ’se’ vectors of the most recent estimation results
    *! to a dataset named ‘outfname’, using ‘nbase’ as the base name for the
    *! dataset columns.
    *!
    *! Also saves variable labels. Each row of the resulting dataset
    *! is a coefficient estimate.
    *!
    program define est2data
    preserve
    args nbase outfname
    drop in 1/`c(N)’
    matrix bvec = e(b)’
    matrix vvec = vecdiag(e(V))’
    svmat bvec, names(`nbase’_est)
    svmat vvec, names(`nbase’_se)
    quietly: replace `nbase’_se = sqrt(`nbase’_se)

    local vnames: rownames bvec
    local numv: list sizeof vnames
    quietly: gen `nbase’_names = “”
    quietly: gen `nbase’_lbl = “”
    forvalues ivar = 1/`numv’ {
    local thisv: word `ivar’ of `vnames’
    quietly: replace `nbase’_names = “`thisv’” in `ivar’
    local thislbl “NA”
    capture local thislbl: variable label `thisv’
    quietly: replace `nbase’_lbl = “`thislbl’” in `ivar’
    }
    keep `nbase’_*
    notes: “e(N) `e(N)’”
    notes: “e(depvar) `e(depvar)’”
    notes: “e(ll) `e(ll)’”
    notes: “e(cmd) `e(cmd)’”
    save `outfname’, replace
    end

  2. Save Estimation Results in Stata » Datanomics says:

    [...] JohnZ posted a solution to saving your coefficient estimates in Stata to a simple dataset. Here is the code: [...]

Leave a Reply