[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: Mata function stata() within program
Thanks for the patient explanations. I completely
misread the sets of quotes. I realize now that it was
just a simple case of concatenation.
--- Nick Winter <firstname.lastname@example.org> wrote:
> This seems right to me. The only thing I'd add is
> that the plus
> signs are not "enclosing" the x and y; they are
> simply the
> concatenation operator.
> In regular Stata, you can do the same thing to put
> strings together:
> . local x = "abc" + "def"
> . di "`x'"
> Or you can concatenate two string variables:
> . generate myvar = var1 + var2
> and so on.
> --Nick Winter
> At 11:40 AM 3/23/2006, you wrote:
> >M Hollis wrote:
> > > --- "William Gould, Stata" <email@example.com>
> > > > My suggested solution is
> > > >
> > > > stata("local hash1 = mod(" + key1 + ",
> > >
> > > Thanks for your detailed discussion about mata
> vs. ado
> > > files. Very helpful. I was wondering, though,
> if you
> > > could provide a manual reference or more of a
> > > description of the syntax in your suggested
> > > above. In particular, I'm wondering what the "
> + key1
> > > + " is doing exactly. I haven't run across that
> > > option in the manual, and it's hard to search
> the help
> > > for something that's just quotes and plus signs.
> > > feel like it could be a very useful function if
> > > could figure out how it works.
> >Not that I am competent, but I think I can answer
> your question partly. Bill
> >might step in to correct me if I were wrong.
> >In general, you have to put a string within the
> parentheses of stata(), hence
> >you have to state:
> >: stata("local hash1 = mod(1,197)")
> >Now, consider the situation that you want to change
> the code to something
> >: stata("local hash1 = mod(x,y)")
> >where x and y are Mata variables. As it stands x
> and y not get "expanded",
> >because they are enclosed in quotes. Hence Stata
> would see
> >-local hash1 = mod(x,y)- which will give an error.
> Bills trickery now is to
> >close the quotation before x, than plug in x as a
> Mata Function, and finally
> >put the rest of the command in quotes again. Hence
> is code should read as
> >: stata(
> > "local has1 = mod" // <- within qoutes
> > x // <- without qoutes
> > ", " // <- within qoutes
> > y // <- without qoutes
> > ")" // <- within quotes
> > )
> >But that is only the first part of the idea. The
> second part is, that x and y
> >has to be "enclosed" between + signs.
> >: stata(
> > "local has1 = mod"
> > + x + // <- within +
> > ", "
> > + y + // <- within +
> > ")"
> > )
> >Don't ask me why, but it works ;-). Probably that
> way Mata knows that it has
> >to calculate something. Maybe someone else can take
> over for the explanation.
> >+49 (030) 25491-361
> >* For searches and help try:
> >* http://www.stata.com/support/statalist/faq
> >* http://www.ats.ucla.edu/stat/stata/
> Nicholas J. G. Winter
> 607.255.8819 t
> Assistant Professor
> 607.255.4530 f
> Department of Government
> firstname.lastname@example.org e
> Cornell University
> falcon.arts.cornell.edu/nw53 w
> 308 White Hall
> Ithaca, NY 14853-4601
> * For searches and help try:
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
* For searches and help try: