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   Grace Jessie <[email protected]>
To   <[email protected]>
Subject   RE: st: doubt on the output format %w.dg
Date   Fri, 18 Mar 2011 03:09:11 +0000

Nick,
thank you for your help.
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.

Thank you!
 
Grace
 
  

> Date: Sun, 13 Mar 2011 09:13:43 +0000
> Subject: Re: st: doubt on the output format %w.dg
> From: [email protected]
> To: [email protected]
> 
> 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/ 		 	   		  
*
*   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