Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: listtex header (AND A BUG/FEATURE IN THE MACRO LANGUAGE)


From   "Newson, Roger B" <[email protected]>
To   <[email protected]>
Subject   st: RE: listtex header (AND A BUG/FEATURE IN THE MACRO LANGUAGE)
Date   Sun, 18 Feb 2007 18:52:22 -0000

Thanks for Kit for demonstrating that the bug (or feature) also occurs
under Linux. I think I have now found the cause of the problem in a bug
(or feature) of the extended macro function

word # of string

(see online help for extended_fcn). For some reason, this indeed seems
to have a 503-character length limit for the output word, and to treat
characters 504 onwards of a word in a string as being part of subsequent
words of the string. The following code demonstrates this:

**** BEGINNING OF Stata CODE - CUT HERE
local head ""
forvalues i = 1/104 {
 local head "`head'1234567890"
}
disp `"`head'"'
local head1: word 1 of `head'
disp `"`head1'"'
local head2: word 2 of `head'
disp `"`head2'"'
local head3: word 3 of `head'
disp `"`head3'"'
local head4: word 4 of `head'
disp `"`head4'"'
local nword: word count `head'
 disp "`nword'"
**** END OF Stata CODE - CUT HERE

This shows that Stata thinks that the local macro -head- contains 2
words with 503 characters each and 1 word with 34 characters, instead of
containing 1 word with 1040 characters. This seems to suggest that there
is a 503-character limit on the length of a string token. I cannot find
any documentation of this limit in -help limits- or in -[P] macro-.

I would definitely like to know whether this limit is a bug or a
feature, and if there are any plans to fix it in the near future.
-listtex- uses the extended macro functions

word count string

and

word # of string

to be able to produce multiple header or footer lines if the user
specifies these in the -headlines()- or -footlines()- option. It is a
pity that this ability currently comes at the price of limiting a header
or footer line length to 503 characters. I would like to be able to fix
this problem.

Best wishes

Roger


Roger Newson
Lecturer in Medical Statistics
Respiratory Epidemiology and Public Health Group
National Heart and Lung Institute
Imperial College London
Royal Brompton campus
Room 33, Emmanuel Kaye Building
1B Manresa Road
London SW3 6LR
UNITED KINGDOM
Tel: +44 (0)20 7352 8121 ext 3381
Fax: +44 (0)20 7351 8322
Email: [email protected] 
www.imperial.ac.uk/nhli/r.newson/

Opinions expressed are those of the author, not of the institution.

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Kit Baum
Sent: 18 February 2007 18:06
To: [email protected]
Subject: st: listtex header

Roger said

As I have
not explicitly included a 502-character limit in -listtex-, and as the
limit to the length of a macro is 67,784 characters (not 502
characters), it seems that the limit that Friedrich and I have
encountered is probably either in Stata or in Windows XP. It does not
seem to be in TextPad, bexause it persists when I use the -type- option
of -listtex- instead of a -using- qualifier, causing the output to be
routed to the Stata log. It is not likely to connected with a limit on
the length of a Stata command line, as that limit is 67,800 in
Intercooled Stata 9 (according to the on-line help for -limits-). Might
it be a problem with the -file- command?

It does not seem to be operating-system specific; I can reproduce the  
same 502-character limit (before a LF is issued) in Unix (Mac OS X).

As the help for -file- suggests that lines of any length can be  
written (with the admonition that lines longer than 67,783 bytes may  
be difficult to handle) this issue must be arising somewhere else. It  
is not -file write- that is the problem:

sysuse auto
forvalues i = 1/52 {
   local head "`head'12345678901234567890"
}

file open test using test.txt,write
file write test "`head'" _n
file close test

will write a file with one line of 1040 bytes. So it must be the  
macval() function that Roger employs that is imposing tne constraint.
I imagine that somewhere along the line someone forgot to bring macval 
() into line with macros > 512 bytes.


Kit

Kit Baum, Boston College Economics
http://ideas.repec.org/e/pba1.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/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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