Title
[D] recast -- Change storage type of variable
Syntax
recast type varlist [, force]
where type is byte, int, long, float, double, str1, str2, ..., str2045, or strL.
Description
recast changes the storage type of the variables identified in varlist to type.
Options
force makes recast unsafe by causing the variables to be given the new storage type even if that will cause
a loss of precision, introduction of missing values, or, for a string variables, the truncation of
strings.
force should be used with caution. force is for those instances where you have a variable saved as a
double but would now be satisfied to have the variable stored as a float, even though that would lead
to a slight rounding of its values.
Examples
Setup
. sysuse auto
Describe the variable mpg
. describe mpg
Change the storage type of mpg from int to byte
. recast byte mpg
Describe the variable mpg
. describe mpg
Describe the variable headroom
. describe headroom
Try to change the storage type of headroom from float to int
. recast int headroom
Describe the variable headroom
. describe headroom
Describe the variable make
. describe make
Try to change the storage type of make from str18 to str16
. recast str16 make
Change the storage type of make from str18 to str20
. recast str20 make
Describe the variable make
. describe make