*! version 1.0 2013-09-25
help use13save12 (vs1.0: 2013-09-25)

Title

use13save2 -- Loading sets of matched Stata 13-files into Stata 10-12 and saving them in older formats readable for the Stata 10-12 user.

Syntax

use13save12 [, folder(string) match(string) subs(string) prefix(string) suffix(string) movenew(string) moveold(string) saveold]

Description

use13save12
is a program that helps out with opening Stata 13 files from within Stata 10-12 and then saving them in Stata 8-12 format
- using use13 (Radyakin, 2013), save and saveold - depending on the version run and the options used.
The command may be applied to a quite generally defined set of Stata datasets within a defined folder and, if selected,
also with respect to all matched corresponding subfolders of that main top-level folder. Original and/or new datasets may
be put into specified - that will be created if neeeded, i.e. if they do not already exist - subfolders.
All options are optional (but not all at the same time, see section What option-combinations will not work? below).

An alternative, secondary, usage might be to use the function from within Stata 13 - even though the original files then
are perfectly readable (hence use are used for loading these cases)- in order to save (sets of) matched
files in an older format readable by other users - as co-workers - that still run Stata 11-12.

Options

folder(string) Defines the main directory from within where to look (or start looking if subs is not left
empty) for files. The default directory is the current working directory (cwd; '.').

match(string) Defines the matching criterion used in order to select files
from the selected directory folder, and - if selected - matched (by subs) subdirectories.
The default is all files in the directory/directories ('*').

subs(string) Defines whether, or not, matched files (by match) in corresponding matched
subdirectories (recursively; based on the here defined matching string criterion) also should be affected.
(Matching must be present at all directory-levels.)

prefix(string) Defines a prefix string to put in front of all new files corresponding
to matched cases.

suffix(string) Defines a suffix string to put at the end of all new files corresponding
to matched cases.

movenew(string) States the subdirectory - compared to the location of the original (Stata 13) file, i.e. for files matched in a
first-level subdirectory this folder would be a subsubdirectory -
where all new files (in older formats) should be put into. If left empty, the new files are saved into the original directory of the corresponding matched file
(and hence prefix and/or suffix must be stated if moveold also is left unassigned, see below under
What option-combinations will not work?). If stating vs then files will be put into subdirectory stata11-12 (if using Stata 13 or as a
default if using Stata 12), stata10-11 (as a default if using Stata 11), stata10 (as a default when running Stata 10),
stata8-10 (if saveold is selected when running Stata 12), or stata8-9 (if saveold is selected when running Stata 10-11).

moveold(string) States the subdirectory - compared to the location of the original (Stata 13) file, i.e. for files matched in a
first-level subdirectory this folder would be a subsubdirectory -
where matched original files (in Stata 13 format) should be moved into. If left empty, the old files are left where they were
(and hence prefix and/or suffix must be stated if movenew also is left unassigned, see below under
What option-combinations will not work?). If stating vs then files will be put into subdirectory stata13.

saveold An indicator for whether, or not, the matched files should be saved in an older format using saveold instead of
by using save. For information on which actually implied output dataset-versions this would imply, see the related information under movenew.

What option-combinations will not work?

(i) When using the command from within Stata 13, the option saveold must be stated.

(ii) If saving, or moving, old and corresponding new files into the same directory
(either if moveold=movenew!="vs" or when both are unassigned), prefixes and/or suffixes must be used. Related to this, it is not possible to replace original files with new ones
(i.e. to delete the original files). Originally, this was planned to be possible by using an option replace, but then some obscure error of (temporary)
read only-permissions preventing saving of new files and hence leading to syntax errors was experienced/run into. On second thought, this might in fact also be an unwanted possibility, since it might
perhaps be seen as good practise not to allow for deleting 'raw' files.

Examples

1. Re-save all (Stata dataset) files in the current working directory in Stata 10-12 format (depending on used Stata version) and move original (Stata 13) files to (created if needed)
subdirectory 'tmp'.

. use13save12 , moveold("tmp")

2. Re-save all files located in the cwd-subdirectory test2 in Stata 10-12 format (depending on used Stata version) in the very same directory, adding strings 'aa_'
as prefixes and '_bb' as suffixes.

. use13save12 , folder("./test2") prefix("aa_") suffix("_bb")

3. Same as Example 1, but here the cwd-subdirectory test3 is used and all subfolders are also searched through - in a hierarchical manner (recursive calls) -
for matching files and - if needed - creation of 'tmp' directories as well.

. use13save12 , folder("./test3") subs("*") moveold("tmp")

4. Combination of Examples 2-3, but applied to cwd-subdirectory test4. Moreover, here all original (Stata 13) files are moved to corresponding
subdirectories stata13 (through assigning 'vs' to moveold).

. use13save12 , folder("./test4") subs("*") prefix("aa_") suffix("_bb") moveold("vs")

5. Similar to Example 4, but here the main directory is the cwd-subdirectory test5 and only files with original suffix est (goverened by option match("est*"))
are matched (and hence affected). Moreover, here the matched original files remain at their initial positions whereas the new files are put into corresponding
subdirectories with name as described in connection with option movenew above (through assigning 'vs' to movenew).

. use13save12 , folder("./test5") match("est*") subs("*") prefix("aa_") suffix("_bb") movenew("vs")

6. Similar to Example 5, but here the main directory is the cwd-subdirectory test6 and all Stata files are matched while only subdirectories
(and, as usual, subsubdirectories within subdirectories, etc.) having suffix test will be affected. Moreover, both original and new files will be put
into corresponding subdirectories named according to the predefined naming structure (through assigning 'vs' to moveold and movenew, see above)
while the saveold option defines both the output format and the movenew subdirectory name (depending on used Stata version).

. use13save12 , folder("./test6") subs("test*") prefix("aa_") suffix("_bb") moveold("vs") movenew("vs") saveold

7. Combination of Examples 5-6, but here the main directory is an absolute path C:/dir1/dir2/dir3/test7. Moreover, both new and old files are
put/moved to the same corresponding subdirectories tmp (located with respect to the corresponding directory of the file at study).

. use13save12 , folder("C:/dir1/dir2/dir3/test7") match("est*") subs("test*") prefix("aa_") suffix("_bb") moveold("tmp") movenew("tmp") saveold

Requires

Stata 10. Moreover, the command depends on the user written function use13 (Radyakin, 2013).

Author

Lars Ängquist

Lars.Henrik.Angquist@regionh.dk

lars@angquist.se

Acknowledgements

Thanks to Matthew White for comments on the related command mvfiles and whose suggestions have been implemented here.

Related commands (downloadable on SSC)

use10save9 - reading Stata 10/11 files and saving them in Stata 8/9 format.

mvfiles - moving set of matched files

renfiles - renaming set of matched files

rmfiles - removing set of matched files

excelsave - exporting set of matched files to Excel (.xls or .xlsx)

Also see

Help: [help pages on] use13 (user-written; SSC),

use, save, saveold, mkdir, varlist, extended_fcn, string functions, _caller().