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   Sun, 13 Mar 2011 09:13:43 +0000

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"

Nick

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

> 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