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/