-------------------------------------------------------------------------------
help for estwrite
-------------------------------------------------------------------------------

Command to backup model estimates on disk

estwrite [namelist using] filename [, id(varname) alt estsave replace append ]

estread [namelist using] filename [, id(varname) estsave describe ]

where namelist is a name, a list of names, or _all; the * and ? wildcards are allowed. A name may also be ., meaning the current (active) estimates.

Description

estwrite exports models previously fitted and stored by estimates store to filename on disk. namelist provides the names of the stored estimation sets to be exported. You may use the * and ? wildcards in namelist. The results estimated last may be indicated by a period (.), even if they have not yet been stored. If no model is specified, estwrite uses the model fitted last.

estread reimports the saved estimation sets from filename. Specify namelist to select the estimation sets to be imported. The default is to import all saved estimation sets.

In both cases, if filename is specified without an extension, .sters is assumed.

estwrite uses the technology behind estimates save to save the estimation sets, but has the following advantages over estimates save:

(1) Multiple sets may be stored in one file. (A similar feature has been added to estimates save in Stata 11. However, estwrite supports named sets and allows storing or retrieving multiple sets in one call.)

(2) The e(sample) (estimation sample) may be stored and recovered using the id() option.

(3) e()-returns that have a name starting with an underscore (e.g. e(_abc)) are preserved.

estwrite can also be used in Stata 8 and Stata 9, where the estimates save command is not available.

o In Stata 9 (or if option alt is specified), estwrite uses its own Mata-based algorithm to store the sets (using the same file format as with the default method).

o In Stata 8 (or if option estsave is specified), the estimates are stored in a Stata dataset using Michael Blasnik's estsave command, which must be installed on the system in this case (see ssc describe estsave). .dta is assumed, if filename is specified without an extension.

Technical note

In Stata 8 and Stata 9 (or if option alt or option estsave is specified) a restored model might differ from the original model in terms of the model's representation in memory (although the represented information is the same). This has to due with the fact that some of Stata's estimation commands (such as, e.g., regress) post their results in e() in a special way that cannot be reproduced by ereturn post, which is used by estwrite to restore the results in Stata 8 and Stata 9.

It may not be possible to replay the full standard output of such a model after importing the model by estread (for example, typing regress without arguments returns error on an imported model that was fitted by regress). However, all results are, in fact, preserved and post-estimation commands such as test or estimates table should work as usual.

Options

id(varname) specifies a unique identifier for the observations and causes the e(sample) to be stored with the estimates. id() specified with estread reimports such estimates.

estsave specifies that the estimates be stored in a Stata dataset using Michael Blasnik's estsave command. estsave is default in Stata 8.

alt causes the estimation sets to be stored without making use of the technology behind estimates save. alt is usually a bit faster than the default method and also results in somewhat smaller file sizes. A disadvantage is, however, that full output may not be replayed for some commands after reimporting the models (see the technical note above). Specify the alt option in Stata 10 if you want to be able to restore the saved models in Stata 9. Similarly, specify alt in Stata 11 if you want to be able to restore the saved models in Stata 10 or Stata 9. alt is default the Stata 9.

replace permits estwrite to overwrite an existing file.

append causes estwrite to add the estimation sets to an existing file. Make sure to use unique names for the added estimation sets. Models saved with or without the alt option may be combined in a single file. The id() option has to be specified if the file to append to was created with id() option (and the values of the ID variables have to coincide). Similarly, the id() option is not allowed if the file to append to was created without id() option.

describe causes estread to display information on the contents of filename without importing the estimation sets.

Returned results

estwrite and estread return in r(names) the names of the exported/imported estimation sets.

Examples

Basic usage:

. sysuse auto (1978 Automobile Data)

. regress mpg price weight (output omitted)

. estimates store model1, title(Model 1) . logit foreign mpg weight (output omitted)

. estimates store model2, title(Model 2) . estwrite * using mymodels (saving model1) (saving model2) (file mymodels.sters saved)

. estimates clear . estread mymodels ------------------------------------------------------- name | command depvar npar title -------------+----------------------------------------- model1 | regress mpg 3 Model 1 model2 | logit foreign 3 Model 2 -------------------------------------------------------

Add models to an existing file:

. regress mpg price weight foreign displ (output omitted)

. estimates store model3, title(Extended Model 1) . estwrite model3 using mymodels, append (appending model3) (file mymodels.sters saved)

. estimates clear . estread mymodels --------------------------------------------------------------- name | command depvar npar title -------------+------------------------------------------------- model1 | regress mpg 3 Model 1 model2 | logit foreign 3 Model 2 model3 | regress mpg 5 Extended Model 1 ---------------------------------------------------------------

Preserve the e(sample):

. sysuse auto (1978 Automobile Data)

. count 74 . mlogit rep78 mpg price weight if rep78>=3 (output omitted)

. count if e(sample) 59 . estwrite . using mymodels, replace id(make) (saving active estimates) (file mymodels.sters saved)

. estimates clear . estread mymodels, id(make) ------------------------------------------------------- name | command depvar npar title -------------+----------------------------------------- . | mlogit rep78 8 -------------------------------------------------------

. count if e(sample) 59

Author

Ben Jann, ETH Zurich, jannb@ethz.ch

Thanks for citing this software as follows:

Jann, B. 2005. estwrite: Stata module to store estimation results on disk. Available from http://ideas.repec.org/c/boc/bocode/s450201.html.

Also see

Manual: [R] estimates