Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: pass matrix as argument to program


From   Ulrich Kohler <ukohler@sowi.uni-mannheim.de>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: pass matrix as argument to program
Date   Wed, 18 Sep 2002 09:06:18 +0000

Just an idea: How about passing only the name of the matrix and letting the 
user define the matrix before issue the command. That is, the user needs to 
specify 

.. matrix A = 0.5 \ 2\ 3
.. mycmd, duration(x) pattern(A)

And the program would be something like:

----------------
syntax, duration(int) pattern(string)
...
* Do something with the matrix
local a = `pattern'[1,1]
di `a'
...
end
-----------------


There are also ways to access the numbers of a numlist directly. Here is just 
one example:

program define myprog
  syntax, num(numlist)
  local a: word 6 of `num'
  di "`a'"
end

.. myprog, num(1(1)10)


regards
uli


> Is there a way of passing a  matrix as an argument to a program ? My
> first hunch (below) didn't work
>
>
> program define simulerpox
> syntax, duration(int) pattern(matrix)
> ....
> end
>
>
> Because my matrix really is a vector, I have thought about passing it as a
> numlist . However, my understanding is that I cannot easily get access to
> the  individual element of the numlist whereas this is possible with the
> matrix using the "el" function
>
> matrix input patmat = (0.5 \ 2\ 3)
> display el(patmat,1,1)
>
> Any suggestions?
>
> Thanks ,
>
> matt

-- 
ukohler@sowi.uni-mannheim.de
http://www.sowi.uni-mannheim.de/lesas

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index