------------------------------------------------------------------------------- help for doubletofloat -------------------------------------------------------------------------------

Change double-type variables to float where possible.

doubletofloat [varlist]


This is simply a convenience, issuing recast float varlist2, where varlist2 is the set of variables in varlist that are of type double. This has some resemblance to, and is intended to complement compress, which does not include the possibility of changing double to float.

doubletofloat would be typically used immediately following compress, and saves you the trouble of seeking out all the remaining double variables. There are some potental complications if you do not preceed it with compress; see notes under Remarks.

If no varlist is specified, _all is assumed.

doubletofloat ignores variables that are not double.


. doubletofloat

. doubletofloat wage income


This is for those instances when you have some double variables which could be stored as float without any loss of precision, but do require float rather than an integer type. Thus, there are fractional values present, but all can be represented exactly using float. Typical values would have fractional parts involving halves and quarters, etc., such as in 2.5, 2.75, and 10.375.

It is best to use this immediately following compress. If you use it without a preceeding compress, you might recast some variables to float which would otherwise become long, int, or byte. If you use it without a preceeding compress, but you do follow it with compress, then those variables that compress would have recast as int or byte (but not long) had it been called first, will still receive that change.

For a similar related program, see floattolong by the same author. Both doubletofloat and floattolong are intended as companions to compress, and would best be used as follows:

. compress . floattolong . doubletofloat

Note that in this sequence, the relative placement of floattolong is not critical, as long as compress comes before doubletofloat. (The sequence doubletofloat, compress, floattolong should also work properly, but it is easiest to remember to place compress first.)

In general data preparation, doubletofloat would usually be called without a varlist; there is little point in calling it with a specific set of variables, since you could just as well type recast float with the same varlist. The exception is where you use it within a program that generates a variable that is initially double, and you want to clean up that one variable without affecting others.


David Kantor, Institute for Policy Studies, Johns Hopkins University. Email dkantor@jhu.edu if you observe any problems.

Also see compress, recast, floattolong, datatypes