Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

re: Re: st: Errors "out of range" for a simple Mata function

From   Christopher Baum <>
To   "" <>
Subject   re: Re: st: Errors "out of range" for a simple Mata function
Date   Wed, 21 Nov 2012 14:14:31 +0000

Nick said

> I was elevating my personal preference only to use views for data that 
> won't change to an implication that you can't do it, which was
> incorrect.
> Given
> local macro generate
> local macro varlist
> local macro touse
> as discussed to date in the thread
> . mata : st_store(., "`generate'", "``touse''", rowsum(st_data(.,
> tokens("`varlist'"), "``touse''")))
> is I think a complete solution.

This is a good illustration of the notion that you don't even need to write a Mata function to use it to complete a Stata task.
But I personally disagree, in my own preferences, with only using views for viewing unchanged data. In my work I do just the 
opposite-- I never use st_store, and always use view matrices to return results to Stata. When creating a single variable, as in this
example, it makes little difference, but I find the syntax much simpler to create a whole set of variables in Mata and return them
to Stata via a view matrix. Many tasks one might employ Mata for create a matrix result, and that can be mapped back onto a
set of Stata variables by merely mentioning the name of the view matrix. For an example, see the code of hprescott.ado on SSC.* 
No doubt something similar can be done with st_store, but I do not find it as straightforward.


* If you're using Stata 12, use -tsfilter hp- for the Hodrick-Prescott filter!

Kit Baum   |   Boston College Economics & DIW Berlin   |
                             An Introduction to Stata Programming  |
  An Introduction to Modern Econometrics Using Stata  |

*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index