Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: doubt on the output format %w.dg


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: doubt on the output format %w.dg
Date   Fri, 18 Mar 2011 09:14:55 +0000

Pleased you solved your problem.

As the original link in particular gave advice to a different question
in the context of a particular example, and your examples appear now
to be quite unrepresentative of your real data, then it does not
surprise that the advice needs some modification for your case.

Indeed. I find for example

. di %2.1f 1e5 + 1/10
100000.1

. di %2.1f 1e6 + 1/10
 1.0e+06

and I regard 1e6 as very greatly bigger than numbers like 1e2. I think
only trial and error will show you how to produce your own favoured
format. It's also a case of your own degree of aversion to unnecessary
spaces, which you don't spell out.

Nick

2011/3/18 Grace Jessie <[email protected]>:

> I need to show an entire variable, so what you typed is helpful but with a little modification.
>
> generate toshow = string(numvar, "%12.2f")
> replace toshow = string(numvar, "%12.0f") if substr(toshow, -2, 2) == "00"
> replace toshow = string(numvar, "%12.1f") if substr(toshow, -1, 1) == "0" &   substr(toshow, -3, 1) == "."
>
> Additionally,  why did you set "w" one bigger than the decimal places in "%w.df"? If I do so, most of the values are
>  showed in exponential format. In an early posting, you mentioned "Use something like %2.1f and Stata will just assign enough space automagically, unless the number is very greatly bigger."  Maybe my number is too big. How to decide "w"?  What I can do is to set the "w"
>  large enough.

Nick Cox

>> You are inventing your own format -- unless someone recognises this as
>> an existing format.
>>
>> For an individual number, the choice could be something like
>>
>> local number = <whatever>
>> local show : display %3.2f `number'
>> if substr("`show'", -2, 2) == "00" {
>> di `number'
>> }
>> else if substr("`show'", -1, 1) == "0" {
>> di %2.1f `number'
>> }
>> else di "`show'"
>>
>> To show an entire variable this way I guess you'd need to work with
>> something like
>>
>> generate toshow = string(numvar, "%3.2f")
>> replace toshow = string(numvar, "%1.0f") if substr(toshow, -2, 2) == "00"
>> replace toshow = string(numvar, "%2.1f") if substr(toshow, -1, 1) == "0"

Grace Jessie

>> > I want to set one variable to display with two digits to the right of the decimal point if the number of digits to the right of the decimal point is more than 2, otherwise display as it is.
>> > For example.
>> > The value of one variable is "1.2 3.2345 3 5.45"
>> > I hope it to display as "1.2 3.23 3 5.45"
>> > Is there any way?

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index