Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[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 <[email protected]>
To
"[email protected]" <[email protected]>
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.
Kit
* If you're using Stata 12, use -tsfilter hp- for the Hodrick-Prescott filter!
Kit Baum | Boston College Economics & DIW Berlin | http://ideas.repec.org/e/pba1.html
An Introduction to Stata Programming | http://www.stata-press.com/books/isp.html
An Introduction to Modern Econometrics Using Stata | http://www.stata-press.com/books/imeus.html
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/