Save a subset of the dataset in memory to a disk file
subsave [varlist] [if] [in] using filename [, rename(oldvarname_1 newvarname_1 ... oldvarname_n newvarname_n) gsort( gsort_list [ , gsort_options ] ) save_options ]
where gsort_list is a list of one or more elements of the form
[+|-]varname
(as used by the gsort command), gsort_options is a list of options used by gsort, and save_options are options used by save.
Description
subsave saves a subset of the dataset currently in memory, specified by the varlist and/or the if and/or in qualifiers, to the disk filename specified by the using qualifier. This saves the user the trouble of inserting a preserve statement before a save command and a restore statement after a save command. This is especially useful in a group of commands between a preserve command and a restore command, as paired preserve and restore statements cannot be nested. In the output dataset, variables can be renamed, and observations can be resorted.
Options
rename(oldvarname_1 newvarname_1 ... oldvarname_n newvarname_n) specifies a list of pairs of variable names. The first variable name of each pair specifies a variable in the output dataset, which is renamed to the second variable name of the pair. This option may be used to change the names of output variables to prevent name clashes, especially if the output dataset is to be match merged with the old dataset using merge.
gsort( gsort_list [ , gsort_options ] ) specifies a generalized sorting order (as recognised by gsort) for the observations in the output dataset specified by using. If rename() is specified, then gsort() must use the new names.
save_options are options used by save.
Examples
. subsave make mpg weight foreign using trash1
. subsave if foreign using trash1, replace
. subsave make weight price in 1/50 using trash2, replace
. subsave make mpg weight foreign using trash1, replace rename(mpg mileage weight pounds) gsort(make -foreign)
Author
Roger Newson, Imperial College London, UK. Email: r.newson@imperial.ac.uk
Also see
Manual: [D] gsort, [D] merge, [D] save, [D] use On-line: help for gsort, merge, save, use