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

st: Can Stata read string variables without stripping blanks?


From   Roger Newson <[email protected]>
To   [email protected]
Subject   st: Can Stata read string variables without stripping blanks?
Date   Tue, 15 Oct 2002 15:23:33 +0100

Hello all

Does Stata have a way of reading string variables in fixed format without stripping leading and trailing blanks? I ask because, if I type

infix line1 1-80 using intext.ado,clear

then I find that the variable -line1- which is created contains the first 80 characters of each line of -intext.ado- minus any leading and trailing blanks. I would like it to contain the first 80 characters of each line of -intext.ado- including leading and trailing blanks (The file -intext.ado- is in fact a Stata program file with indentations.) What I am looking for is a kind of inverse to the -runtogether- option in -outfile- that was provided in response to a thread I started in 2001 re writing program generators in Stata. (Thanks again to the people at StataCorp for responding so promptly).

I realise that there might be a very long-winded solution to this problem using the -file- command to read the file as a binary file byte by byte and to build up the variable -line1- byte by byte using a series of statements of the form

replace line1=line1+`"`curbyte'"' in `i1'

(assuming that the macro -curbyte- contains the most recently read byte and that the macro -i1- contains an observation sequence number). However, I was wondering whether there was a simpler way.

I tried the option of using -file- to read the file line by line as an ASCII file. However, the problem there is that -file- stores each line in a macro. If the line is stored in a macro named -curline-, and the sequence number of the current line of the file is stored in a macro named -i1-, and I type

replace line1=`"`curline'"' in `i1'

then Stata resolves any macro references in the value of -curline-.

I suspect that life would be easier if there was a string function named -local- which delivered the value of a local macro. Then I might type

replace line1=local("curline") in `i1'

and the variable -line1- would then contain the value of the macro -curline- in one observation, without any macro substitutions. However, I can't find any reference to a function like the hypothetical -local-, either in the Stata manuals or in the on-line help.

Best wishes (and thanks in advance for any help)

Roger

--
Roger Newson
Lecturer in Medical Statistics
Department of Public Health Sciences
King's College London
5th Floor, Capital House
42 Weston Street
London SE1 3QD
United Kingdom

Tel: 020 7848 6648 International +44 20 7848 6648
Fax: 020 7848 6620 International +44 20 7848 6620
or 020 7848 6605 International +44 20 7848 6605
Email: [email protected]

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

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