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

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


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: file write vs. display; trimming; string()
Date   Thu, 29 Apr 2004 16:23:48 +0100

Try something like 

	tempfile foo
	tempname bar 
	file open `bar' using `foo', write 
	forval i = 1/10 { 
		local val : di %5.0f `i' 
		file write `bar' _n "`val'" 
	} 
	file close `bar' 

Nick 
[email protected] 

David Kantor
> 
> 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.

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