Data Importing and Exporting in Stata

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome to another state a tutorial video in this video I'm going to show you how to import and export data into and out of Stata I have here is our data set of 100 Indiana residents and their sex age race education and total income I'm going to now import this into Stata one of the most straightforward ways that we can do this is to simply select the entire data set including the variable names in the top row copy go back to Stata and then go into the data editor that's the one with the pencil not the magnifying glass and then simply paste Stata will now ask us if we want to use the first row as variable names or as values and we're going to select variable names the data will now be pasted into the editor we can now go on and use this data in any way we choose I'm now going to clear this out and show you a different way that we can import the data let's go back to the editor real quick and notice that everything is gone I'm now going to go to file import we now select the type of file that we're going to import this is an Excel spreadsheet so I'll click that now click browse and select the file if your Excel workbook has more than one sheet then you'll be able to select that from the drop-down menu ours does not now notice that there's again the choice import first row is variable names I'm going to select this and that will pop those names from the first row up into the variable names fields now I can also switch these variable names to all uppercase or all lowercase I'll select lowercase and now I will press ok the data has now imported I'll go back to the data browser and we can see that everything is imported just like before as we saw in the drop down menu which I'll pull up again Excel spreadsheets are not the only type of data set that you can import into Stata you can also use delimited text files so tab separated or comma separated values I will demonstrate that right now I've opened up notepad and I'm just going to quickly create a tab separated data set so for example let's say that we have prices and then quantities separated by tabs and I'll just put in some values I'll now save this into our working directory just like before we can copy and paste tab-separated data directly into the data editor like so or we can use the import command so I'm going to go and now choose text data delimited browse for my file the default setting is to automatically detect the delimiter but if you need to specify that you can this would be relevant if you had tab separated data that had commas in it or something like that we can see from the preview that Stata has accurately detected that we're using tab separated data we can also see that Stata has automatically detected variable names we can make sure by setting this to always that would ensure that price and quantity would be in the headers I'm going to click OK go back to the data editor and we can see that the tab separated data has imported properly we can now save this data set in the Stata DTA format I'll do that right now now in future we'll be able to simply use the open command and pull this data set right up in a native state of format if you want to export your data from the Stata format into either txt Excel or something else you can do that as well and use the export command so I'm going to click data to excel spreadsheet first thing you need to do is specify variables if you leave it empty as it says it will automatically include everything but if I just typed price it would include only the price variable but I'll get rid of that okay name your file and then I'm going to also select save variable names to first row an excel file to include our header and then click OK the export cleated so let's go and check if it worked going to open up text data and there we go our data set is right here in Excel that's all I have to say about importing and exporting data using Stata if you have any questions please let me know
Info
Channel: SebastianWaiEcon
Views: 37,899
Rating: 4.8561153 out of 5
Keywords:
Id: MR776iqsRAg
Channel Id: undefined
Length: 6min 48sec (408 seconds)
Published: Wed Jan 04 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.