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

st: file write vs. display; trimming; string()


From   David Kantor <[email protected]>
To   [email protected]
Subject   st: file write vs. display; trimming; string()
Date   Thu, 29 Apr 2004 10:44:54 -0400

Hi.

I have a little problem which I wonder if any of you have dealt with.

If I do
display %5.0g 23

I get " 23", that is, the textual form of the number is right-justified in a field of five characters.
(In real life, I have something more complex in place of the 23.)

Nut if I do
file write filehandle 5%.0g (23)

then the leading spaces are trimmed, and thus it is no longer right-justified.

I thought I could use string(23, "5%.0g"), but this, too, trims spaces.

I can think of a solution (untested):
local t1 = string(23, "5%.0g")
local len1 = length("`t1'")
local len2 = 5 - `len1'
file write filehandle _dup(`len2') " " "`t1'"

-- but I wonder if there is a simpler solution that I've overlooked.

Thanks if anyone can help.
-- David


David Kantor
Institute for Policy Studies
Johns Hopkins University
[email protected]
410-516-5404

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