Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Re: problem with embedded quotes in strings

From   "David E Moore" <[email protected]>
To   [email protected]
Subject   st: RE: Re: problem with embedded quotes in strings
Date   Wed, 22 Jun 2005 09:52:23 -0700

I guess I wasn't especially clear.  It isn't that Stata can't grab a line from
an ASCII file and display it correctly on screen, with or without quotes.  The
problem is that you can't do much with that line unless it's less than the
length limit for string variables, since all string functions or, more
generally, any expressions involving that line will truncate it if it is longer
than the limit for strings.  You couldn't, for example, sort a file using
numeric data toward the end of each line, if the lines were longer than 80
characters (or 244 for Stata/SE), because you have no reliable way to get at
that data.  Moreover, you'd still have to move the data from the macro into
Stata variables in order to sort the file.

Now, I suppose one might be able to chop a long macro into smaller pieces using
only macro extended functions, store the pieces in string variables, fiddle with
each of those pieces to locate and extract the sort fields, sort everything, and
reconstruct the original lines via macros.  But that seems a daunting task given
all the opportunities for errors - not to mention the time it would take to do
all this with a file that contains more than a few records.


-----Original Message-----
From: [email protected]
[mailto:[email protected]]On Behalf Of Kit Baum
Sent: Wednesday, June 22, 2005 6:22 AM
To: [email protected]
Subject: st: Re: problem with embedded quotes in strings

I'm not fully convinced that this sort of thing is impossible in Stata
pre version 9 (although it is probably much more elegantly and
efficiently done as you have, in Mata). If you construct a
tab-delimited file such as

1       john's string   999
2       mary's string   998
3       nick's "Ole Nick" string        997

and apply the program ltype, which appears in Stata 8.x -help file-, it
handles the embedded single and double quotes successfully:

. ltype test.raw
    1  1 john's string   999
    2  2 mary's string   998
    3  3 nick's "Ole Nick" string        997

Since macros may be very long indeed (even in Stata 8.x) the limit on
length is not really binding.

Kit Baum, Boston College Economics

On Jun 22, 2005, at 2:33 AM, David wrote:

>  Those who have written ado
> programs will note that nearly everything I accomplished could have
> been done in
> Stata if not for the built-in limit on string length and/or
> (mis)handling of
> quotes.  It is unfortunate that it took Mata to do this, because it is
> not
> available to anyone using an older release of Stata.  On the other
> hand, as a C
> programmer, I can't recommend Mata enough.  It's actually better than
> sliced
> bread....
> D. Moore

*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index