Bookmark and Share

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

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

re: Re: st: Code from Stata Journal

From   Christopher Baum <>
To   "" <>
Subject   re: Re: st: Code from Stata Journal
Date   Sun, 30 Oct 2011 10:17:54 -0400

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

mata: pp("brighton","20111030","1009",42,"ne",5)
di `"`line'"'

Kit Baum   |   Boston College Economics & DIW Berlin   |
                             An Introduction to Stata Programming  |
  An Introduction to Modern Econometrics Using Stata  |

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index