Statalist


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

st: RE: float function question


From   "Kieran McCaul" <Kieran.McCaul@uwa.edu.au>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: float function question
Date   Wed, 17 Jun 2009 11:21:44 +0800

...

I feel silly all the time, David - you get used to it.

This works:

clear
input float x
0.00
0.01
0.03
0.10
0.30
1.00
end
generate str4 x_str = ""
replace x_str = "0.00" if float(x) == float(0.0)
replace x_str = "0.01" if float(x) == float(0.01)
replace x_str = "0.03" if float(x) == float(0.03) 
replace x_str = "0.10" if float(x) == float(0.1) 
replace x_str = "0.30" if float(x) == float(0.3) 
replace x_str = "1.00" if float(x) == float(1.0) 
list, clean


but so would:

gen x_str = string(x,"%4.2f")


______________________________________________
Kieran McCaul MPH PhD
WA Centre for Health & Ageing (M573)
University of Western Australia
Level 6, Ainslie House
48 Murray St
Perth 6000
Phone: (08) 9224-2701
Fax: (08) 9224 8009
email: Kieran.McCaul@uwa.edu.au
http://myprofile.cos.com/mccaul 
http://www.researcherid.com/rid/B-8751-2008
______________________________________________
If you live to be one hundred, you've got it made.
Very few people die past that age - George Burns

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of David Airey
Sent: Wednesday, 17 June 2009 10:56 AM
To: Statalist
Subject: st: float function question

.

Why does the float function not work like this? I feel silly.

clear
input float x
0.00
0.01
0.03
0.10
0.30
1.00
end
generate str4 x_str = ""
replace x_str = "0.00" if float(x) == 0.0
replace x_str = "0.01" if float(x) == 0.01
replace x_str = "0.03" if float(x) == 0.03
replace x_str = "0.10" if float(x) == 0.1
replace x_str = "0.30" if float(x) == 0.3
replace x_str = "1.00" if float(x) == 1.0
list, clean

which gave

. list, clean

          x   x_str
   1.     0    0.00
   2.   .01
   3.   .03
   4.    .1
   5.    .3
   6.     1    1.00


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index