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]
st: mata programming - input type
From
Tomáš Houška <[email protected]>
To
[email protected]
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/