More problems passing values into and out of routine....
I have been able to use -syntax- to, say, pass one matrix to a routine and
return it as another, e.g.,
syntax, input(name) output(name)
allows me to run a routine, say -gprvector- giving it matrix A and
returning a new matrix B:
gprvector, input(A) output(B)
and then I have a new matrix, B, such that
matrix list B
executed after
gprvector, input(A) output(B)
shows me my results.
But what if I want the routine to return, on occasion, some values
calculated over these matrixes such as (for simplicity!) the number
of non-zero cells in the new matrix, B? Assume that this number is
being calculated within the -gprvector- routine in the local `cells':
How do I return this result along with the new matrix, B? I tried (by
analogy)
syntax, input(name) output(name) [cells(name)]
and then executed
gprvector, input(A) output(B) cells(z)
but the follow-up command
dis z
draws a blank.
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)
On Tue, 19 Jul 2005, David Kantor wrote:
> 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/
>
*
* 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/