Bookmark and Share

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: beginer's mata function in dofile


From   tashi lama <[email protected]>
To   <[email protected]>
Subject   st: beginer's mata function in dofile
Date   Fri, 3 Aug 2012 18:05:48 +0000

Hello all, 
    I am trying to learn Mata and this is my first do file with mata function. I mimicked the code originally written by  William Gould of StataCorp titled "Mata Matters: Creating new variables-sounds boring, isn't". 

bp1   bp2   bp3   bp4   bp5 |
  |-----------------------------|
  | 170   168   166   163   161 |
  | 158   156   154   151   147 |
  | 161   158   155   151   147 |
  | 155   153   151   148   144 |
  | 158   160   160   161   162 |

begin do-file mata1.do
capture program drop nn
mata: do_trend_var("b", "bp1 bp2 bp3 bp4 bp5")
list
end
function do_trend_var(string scalar newvarname, string scalar varnames)
{
real matrix Y
real colvector b
real scalar idx
st_view(Y, ., varnames)
b =1\2\3\4\5
idx = st_addvar("float", newvarname)
st_store(., idx, b)
}
exit
nn

when I run, stata isn't happy and throws back
 <istmt>:  3499  do_trend_var() not found
r(3499);

Any idea? 

Thanx always 		 	   		  
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index