Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Re: st: Code from Stata Journal


From   Pedro Nakashima <nakashimapedro@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: Re: st: Code from Stata Journal
Date   Mon, 31 Oct 2011 06:53:50 -0200

Mr Baum, thanks  for the correction.. It's very important for a person
who is learning the language Mata (like me) ..

2011/10/30 Christopher Baum <kit.baum@bc.edu>:
> <>
> There is indeed a typographical error in the rendering of compound double quotes on pp. 613, repeated on p. 615, of the Gould "Mata matters: file processing" article in the SJ 9:4 PDF. The original code works, no doubt (although annoyingly it is not downloadable from the SJ site), but in typesetting a couple of characters were mangled.
>
> The issue here is that the sprintf function needs to put quotes around the string scalars in its output, but not quote the real scalars (numbers). The typo is that the first character of the first argument should be the `, which you usually use on the left side of a local macro dereference, and the last character should be the ', usually ending a local macro dereference.  The digraphs `" and "' (accent grave - quotation) and (quotation - apostrophe) are known as compound double quotes, and are needed to quote a string that itself contains quotes.
>
> This code works:
>
> clear all
> mata:
> void function pp(
>        string scalar sname,
>        string scalar date,
>        string scalar time,
>        real scalar temp,
>        string scalar wind,
>        real scalar speed
> )
> {
>
> st_local("line", sprintf(`""%s" "%s %s" %g "%s" %g"' , sname, date, time, temp, wind, speed))
> }
> end
>
> mata: pp("brighton","20111030","1009",42,"ne",5)
> di `"`line'"'
>
> Kit Baum   |   Boston College Economics & DIW Berlin   |   http://ideas.repec.org/e/pba1.html
>                             An Introduction to Stata Programming  |   http://www.stata-press.com/books/isp.html
>  An Introduction to Modern Econometrics Using Stata  |   http://www.stata-press.com/books/imeus.html
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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   |   Site index