-format-
Example:
clear
set obs 2
gen x = 1.1234567
gen y = 2
l
format * %09.3f
l
format * %9.3f
l
format * %9.3g
l
Just to clarify, the * in the format command is a varlist (the * means "all" in pretty much any language). You could give it x or y instead. See -help varlist- for more fun with varlists.
And to further clarify, the 0 before the rest of the format string (as in the zero in %09.3f) makes Stata pad out zeroes. Why would you ever want this? Well, say you had a state/county code for Augusta, Alabama (these are known as FIPS codes). That's state 01, county 001. So the combined code is 01001. Now say you actually wanted it to export as 01001 instead of 1001, as it would if it were numeric....
clear
set obs 1
gen fips = 01001
l
tostring fips, replace format(%05.0f)
l
Thursday, January 27, 2011
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment