Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: Re: st: Code from Stata Journal


From   Pedro Nakashima <[email protected]>
To   [email protected]
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 <[email protected]>:
> <>
> 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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index