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

Re: st: Variable number of matrixes as arguments


From   David Kantor <[email protected]>
To   [email protected]
Subject   Re: st: Variable number of matrixes as arguments
Date   Tue, 19 Jul 2005 18:44:01 -0400

At 06:36 PM 7/19/2005 -0400, Herb Smitt wrote:
This is a programming question.

I have a program, "project" that takes two matrixes (say, "matrix1" and
"matrix2") and a number (say, "n") and returns a result as a matrix (say,
"matrix0").  I have no trouble writing a program that calls the routine
via

. project matrix0 matrix1 matrix2 n

along the lines

. program project
.       args result history ratios years

where "result" etc. are local macros corresponding to the arguments being
passed in the call or command line.

My problem is:  What happens if sometimes when I want to run the routine,
I want to pass another argument, say, "matrix3", but sometimes I do not?
If I make this argument the last in the local macros, e.g.,

. program project
.       args result history ratios years births

how can I see whether "matrix3" was passed to `births' or not?  I.e.,

. project matrix0 matrix1 matrix2 n matrix3

versus

. project matrix0 matrix1 matrix2 n        ?

Similarly, how can I allow "n" not to be specified in the call line?

        All of this is simple with "syntax" instead of "args", except I do
not understand how to pass (call) matrixes using syntax...

        Thanks in advance for any help....

        --Herb Smith

Professor of Sociology and
Director, Population Studies Center
3718 Locust Walk CR
University of Pennsylvania
Philadelphia, PA  19104-6298

[email protected]

215.898.7768 (office)
215.898.2124 (fax)
I believe you can use the -namelist- feature of -syntax-.

Another possibility (if namelist doesn't prove useful) is as a set of options:
 syntax ... , mat1(string) mat1(string) [mat3(string) ]

HTH
--David

David Kantor
Institute for Policy Studies
Johns Hopkins University
[email protected]
410-516-5404

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index