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, **statalist.org** is already up and running.

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

From |
Tomáš Houška <xbender@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
st: mata programming - input type |

Date |
Wed, 20 Mar 2013 23:16:41 +0100 |

Dear Stata list, I am trying to write this loop (here I give an example in "stata language", but I am aware that this will never work as mata cannot be processed within Stata loop): Example: levelsof time_period, local(period_id) foreach period of local period_id { mata //import STATA matrices EPSILON = st_matrix("EPSILON_M`period'") PRICE = st_matrix("PRICE_M`period'") SHARE = st_matrix("SHARE_M`period'") BETA = EPSILON :* ( (SHARE *(1:/PRICE)') ) st_matrix("BETA`period'",BETA) end } Which means I have several matrices, each marked by period number and I am trying to perform some operations on them (here I give a simplified example of my code). I would like to create a mata function that would take "period_id" as an input (period_id is always in integer) and process the mata code, resulting in creating new matrix BETA`period_id'. So far I have been able to come up with this: Example 2: mata mata clear void mc_estim(string scalar period) { //import STATA matrices EPSILON = st_matrix("EPSILON_M`period'") PRICE = st_matrix("PRICE_M`period'") SHARE = st_matrix("SHARE_M`period'") BETA = EPSILON :* ( (SHARE *(1:/PRICE)') ) st_matrix("BETA`period'",BETA) } end * run mata function with a selected input mata mc_estim(534) But I am not sure how to use the "input" in the mata function code (I expect that the notation is different from Statas local macros....) I would appreciate any help on this. Thank you! T. * * 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/

**Follow-Ups**:**Re: st: mata programming - input type***From:*Nick Cox <njcoxstata@gmail.com>

- Prev by Date:
**Re: st: Incomplete results of linear regression with interaction variable** - Next by Date:
**Re: st: Interpretation of Two-sample t test with equal variances?** - Previous by thread:
**st: ordered logistic integration problems** - Next by thread:
**Re: st: mata programming - input type** - Index(es):