Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: how to use macro `using' in a program which calls for mata function


From   Oleksandr Shepotylo <shepotil@econ.umd.edu>
To   Stata <statalist@hsphsun2.harvard.edu>, Oleksandr Shepotylo <shepotil@econ.umd.edu>
Subject   st: how to use macro `using' in a program which calls for mata function
Date   Wed, 10 May 2006 14:46:04 -0400

Hi Satalist users,

I am writing a program that at some point call for mata function:

mata:
void spatlag(string scalar varname, string scalar newvarname, string scalar path)
{
real colvector x, y
st_addvar("float", newvarname)
st_view(x,., varname)
st_view(y,., newvarname)
fh = fopen(path, "r")
W=fgetmatrix(fh) y[.,.]=W*x
}
mata mosave spatlag(), dir(C:\ado) replace
end


It works fine when I type, for example
mata spatlag("var", "newvar", "C:\matrix1")


but it refuses to work if I use it in a program:

program define sptreg

syntax [varlist] [using]
...
mata spatlag ("var", "newvar", `"`using'"')

when I type

sptreg varlist using "C:\matrix1"

it gives an error message:

file using `"C:\weight"' not found
fopen(): 601 file not found
spatlag(): - function returned error
<istmt>: - function returned error

If I change my program by removing double quotes:

program define sptreg

syntax [varlist] [using]
...
mata spatlag ("var", "newvar", "`using'")

it returns another error message:

invalid expression
r(3000);
I guess that the whole problem is how to use quotes properly but I can not find
mistake.

Thanks,

Oleksandr.



*
* 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