# re: st: R and Stata efficiency

 From David Airey To statalist@hsphsun2.harvard.edu Subject re: st: R and Stata efficiency Date Tue, 10 Jul 2007 09:42:16 -0500

.

I wrote in a summary of some instances where an R user felt they had things better in terms efficiency at the command line. Not spending as much time at Stata _and_ R that would give me a better feeling for whether comments made were born out of familiarity with both command lines (and fair judgement) or just one (and relative ignorance of best practices), I posted.

Phil Schumm kindly replied with some excellent comments. Especially appreciated was the prefix, -estimates for-, because my R user friend

One final comment RE use of stored results. In R, once you have fit several models and stored their results you can do something like this:

plot(results)
plot(other_results)

Now, suppose you've done the same in Stata. What I often see users do is the following:

est restore results
rvplot
est restore other_results
rvplot

However, this is unnecessary. Instead, you can simply do

est for results: rvplot
est for other_results: rvfplot

Notice that the -estimates for- prefix goes a long way toward reducing the difference between Stata and R in the ease with which you can use stored results.
I definitely have been overtyping as Phil described, and look forward to using the -estimates for- prefix (see help estimates in Stata). Admittedly, this prefix has stared me in the face as many times as I've looked up help for estimates, but it is easy to miss how best to use options best.

One other comments from the R user regarding efficiency was about nesting functions:

One other issue is that the result of a command (sic in Stata) cannot be used directly as the argument of another commmand. In R, I can do something like

dhdbeta = A %*% diag(exp(aacoef))

in which, exp() gives the exponential values of the elements in aacoef, then diag() makes a matrix with the diagonal being those exponential values, then the matrix is multiplied on the left by another matrix A. The exp() and diag() are calculated on the fly and discarded afterwards. Their values are not used elsewhere and thus there is no need to save them explicitly just for the next step. While in Stata, I have save them.

```--
David C. Airey, Ph.D.
Research Assistant Professor

*
*   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/
```