help csvconvert -------------------------------------------------------------------------------


csvconvert - module for gathering multiple comma-separated values (.csv) files into one single Stata (.dta) dataset.


csvconvert input_directory [, options]

Note: all .csv files must be placed in the same directory; input_directory is the directory where the .csv files must be stored.

options Description ------------------------------------------------------------------------- output_file(file_name) file_name is the name of the .dta file; default is "output.dta". output_dir(output_directory) output_directory is the directory where the output file is saved; default is input_directory. input_file(.csv file list) names of the .csv files placed in input_directory to be converted; you must specify the extension .csv for each file name included in the list (see examples below). If this option is not specified, csvconvert takes into the process all the .csv files stored in input_directory. ------------------------------------------------------------------------- Double quotes must NOT be used to enclose input_directory nor output_directory, even if the directory path contains spaces.


csvconvert appends a set of .csv files into one single file, which is saved in the .dta format, immediately readable into Stata. This command suits the case in which the researcher holds multiple data files differing by - for example - a period variable, typically year.

By default, csvconvert creates a new variable, _csvfile, containing the name of the .csv file from which the observation originates. At the end of the process csvconvert displays a message with the number of the original .csv files that have been included in the .dta file. (this information can become useful to double check that all the .csv files have been converted into the .dta file).


Donwload trail sample from my webpage and store the files in a directory you created - for example C:\Data\worldbank.

Check that all the .csv files are in the same directory - in this example C:\Data\worldbank . dir C:\Data\worldbank\*.csv

The following command creates the file output.dta and saves it in the directory C:\Data\worldbank . csvconvert C:\Data\worldbank

The following command creates the file wb_data.dta and saves it in the directory C:\Data\wb dataset . csvconvert C:\Data\worldbank, output_file(wb_data.dta) output_dir(C:\Data\wb dataset)

The following command includes in output.dta only the selected .csv files wb2008.csv and wb2009.csv . csvconvert C:\Data\worldbank, input_file(wb2008.csv wb2009.csv)

Similar to the commands above: the files wb2008.csv and wb2009.csv are stored into wb_data.dta, which is saved in C:\Data\wb dataset . csvconvert C:\Data\worldbank, input_file(wb2008.csv wb2009.csv) output_file(wb_data.dta) output_dir(C:\Data\wb dataset)


Alberto A. Gaggero, University of Pavia, Italy

Also see

Manual: [D] append, [D] insheet

Help: [D] append, [D] insheet