(Though in my experience it is better to remove the extraneous data from Excel, as its easy to forget something here!)
#IMPORT DATA FROM EXCEL TO STATA 13 MANUAL#
This loads just the first 100 rows ( a/b is a “numlist” counting from “a” to “b” by integers).įor further details, see help use, specifically the manual which has the full documentation.ĭata stored in Excel can be ported into Stata easily. We’ll discuss later about conditional statements.Īlternatively, if you have a very large data set, you can load in a small chunk of it. The statement gender = “male” is a conditional statement which only loads male patients. Here, using and if are subcommands, which we will see used more as the day goes on. Use bp heartrate date if gender = "male" using patientdata As this is a lesser-used option we won’t go into too much detail, but as an example, if I wanted to load only the variables named “bp”, “heartrate” and “date” from the data set “patientdata”, restricted to male patients, I might use something like However, if your data is very large, it might be handy to only load in some of it rather than the entire thing.
![import data from excel to stata 13 import data from excel to stata 13](https://aws1.discourse-cdn.com/business6/uploads/dynamobim/optimized/3X/3/2/32bc36483ea6a9c10abd2d19495df5cd9b7d235d_2_1024x640.png)
Generally I would recommend loading the full data and then discarding the extraneous information. You can load only a subset of the data into the program at a time. As with all commands, the use command will be echoed in the Results after using the dialog box, allowing you to add it to a Do-file.Īs with sysuse and webuse, the clear option discards the existing data regardless of unsaved changes. If the location of your file is much different than your working directory, it can be quicker just to use the menu “File -> Open” and use the file open dialog box instead. It is never wrong to use quotes (just not always required), so perhaps that’s a safer option. Use "C:\Documents\Stata\My Project\My Data"
![import data from excel to stata 13 import data from excel to stata 13](https://www.pauloldham.net/images/excel/file_import.png)
Note that if the path (or file name) contains any spaces, you need to wrap the entire thing in quotes: For example, if your working directory is “C:\Documents\Stata” and the file you are looking for, “mydata”, is in the “Project” subfolder, you could open it with any of the following: If the file exists in a different directory, you will need to give the full (or relative path). If you are willing to dispose of your changes, you can either manually do it by callingĪs you may have deduced from the sysuse and webuse commands above, the command to load local data is use:Īs discussed in the working directory section, Stata can see only files in its working directory, so only the name of the file needs to be passed. If you make any modifications to your data, Stata will try and protect you by refusing to load a new data set which would dispose of your changes. To see a list of the built-in data sets, useĪuto.dta citytemp.dta nlsw88.dta tsline2.dtaĪuto2.dta citytemp4.dta nlswide1.dta uslifeexp.dtaĪutornd.dta educ99gdp.dta pop2000.dta uslifeexp2.dtaīplong.dta gnp96.dta sandstone.dta voter.dtaīpwide.dta lifeexp.dta sp500.dta xtline1.dtaĪnd use sysuse again to load data, for example the auto data which contains characteristics of various cars from a 1978 Consumer’s Report magazine. Additionally, most (if not all) of the examples in Stata help will use these data sets. 5.8.2 Converting strings into labeled numbersīefore we turn to using your own data, it is useful to know that Stata comes with a collection of sample data sets which you can use to try the Stata commands.
![import data from excel to stata 13 import data from excel to stata 13](https://i.ytimg.com/vi/3RPDnJ9HmKU/maxresdefault.jpg)