Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Formatting fields


From   "Svend Juul" <SJ@SOCI.AU.DK>
To   <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Formatting fields
Date   Sat, 8 Oct 2005 12:38:24 +0200

Chris wrote:

I have two files one file has ID in the form str10 the other in the form 12.0g.
I want to merge the data by the ID
When I perform a command to change the str var to numeric, the new numeric
field comes in as a float  %9.0g
When I reformat that field to 12.0g, the field values change completely.
--------------

For long IDs string variables are recommended. In numeric variables the
standard float type has a precision of 7 digits, so it must be declared
double. Take a look with -describe- if your numeric ID is -double- (this
has nothing to do with the format). If it is -float- you have a serious
problem.

If the numeric ID is double, OK. If the name of the numeric ID is -idn-,
create the corresponding string (ids) by:
   . generate ids = string(idn, "%010.0f")

%010.0f creates a fixed format. The leading 0 means that strings shorter
than 10 characters will have leading 0s rather than blanks.

This works with version 8 and 9. I am not sure about version 6.

Hope this helps
Svend
________________________________________________________

Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6
DK-8000 Aarhus C,  Denmark
Phone, work:  +45 8942 6090
Phone, home:  +45 8693 7796
Fax:          +45 8613 1580
E-mail:       sj@soci.au.dk
_________________________________________________________

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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