In order to read a data file in Stata that uses commas or tabs as delimiters, you can use the “import delimited” command. This command allows you to specify the delimiter used in the data file, whether it is a comma, tab, or any other character. This will ensure that the data is properly imported into Stata and can be used for analysis. Additionally, you can also use the “insheet” command to read in a file with delimited data, but it is important to specify the correct delimiter in order to avoid errors. Overall, using these commands allows for efficient and accurate reading of data files with varying delimiters in Stata.
How do I read a data file that has commas or tabs as delimeters? | Stata FAQ
Consider the file below that contains four variables,
make, mpg, weight, and price.
The file looks like what is shown below (the variable names are indeed the first line of
data.)
make,mpg,weight,price AMC Concord,22,2930,4099 AMC Pacer,17,3350,4749 AMC Spirit,22,2640,3799 Buick Century,20,3250,4816 Buick Electra,15,4080,7827
You can read this kind of file using the insheet command
as shown below.
insheet using comma.txt
We can issue the list command to see if the data was
read properly.
list
make mpg weight price
1. AMC Concord 22 2930 4099
2. AMC Pacer 17 3350 4749
3. AMC Spirit 22 2640 3799
4. Buick Century 20 3250 4816
5. Buick Electra 15 4080 7827 As you can see, the insheet command was pretty smart. It got the variable names
from the first row of the data. It looks at the first row and can get the
variable names from the first row. It also examines the file and
determines for itself whether the data are separated by commas or by
tabs. The exact same command could read the same file but delimited with tabs (you
can try reading https://stats.idre.ucla.edu/wp-content/uploads/2016/02/tab.txt for
yourself). If you would like more information about reading data in Stata, see the
Stata
Learning Module on inputting raw data into Stata.
As an aside, you can actually read the raw data file comma.txt directly
over the internet into Stata, using the following command:
insheet using https://stats.idre.ucla.edu/stat/stata/faq/comma.txt
Cite this article
stats writer (2024). How can I read a data file in Stata that uses commas or tabs as delimiters?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-read-a-data-file-in-stata-that-uses-commas-or-tabs-as-delimiters/
stats writer. "How can I read a data file in Stata that uses commas or tabs as delimiters?." PSYCHOLOGICAL SCALES, 30 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-i-read-a-data-file-in-stata-that-uses-commas-or-tabs-as-delimiters/.
stats writer. "How can I read a data file in Stata that uses commas or tabs as delimiters?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-read-a-data-file-in-stata-that-uses-commas-or-tabs-as-delimiters/.
stats writer (2024) 'How can I read a data file in Stata that uses commas or tabs as delimiters?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-read-a-data-file-in-stata-that-uses-commas-or-tabs-as-delimiters/.
[1] stats writer, "How can I read a data file in Stata that uses commas or tabs as delimiters?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.
stats writer. How can I read a data file in Stata that uses commas or tabs as delimiters?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
