Stata Do File Bookmark
If you do not see the menu on the left click here to see it
From Excel to Stata
The ‘quickie’ way
This is the easiest way to put data in Excel into Stata, just copy-and-paste. Select and copy in Excel and paste in Stata’s data editor.
Let’s check out one other dataset. Click here to download the data for this section. For convenience, save it in your H: drive in a folder name “statadata” (make it if you do not have it).
Toggle Bookmark: Turn on or off the bookmark on the current line. Bookmarks are a way to move quickly within the do-file. They are quite useful in long do-files or when. 13 Using the Do-file Editor—automating Stata The File menu The File menu of the Do-file Editor includes standard features found in most text editors. The excel file should look like this: Once in excel, select the table, copy it (Ctrl-C or Edit - Copy) and paste it into the Stata editor by clicking in the data editor icon mark by the red arrow below or by typing edit in the command window. If you get the following message just click OK.
Var1 | Area in Square Kilometers |
Var2 | Area in Square Miles |
Enya full album torrent. Var3 | Population |
Var4 | Imports |
Var5 | Exports |
Var6 | Type of Regime |
The excel file should look like this:
Once in excel, select the table, copy it (Ctrl-C or Edit - Copy) and paste it into the Stata editor by clicking in the data editor icon mark by the red arrow below or by typing edit in the command window.
If you get the following message just click OK. An go back to the “Data Editor” window.
The data editor looks like a spreadsheet (but it is not). Paste the data from excel. The first row will become the variable names. If the first row does not have variable names they will be named var1, var2, var2, etc.:
WARNING: When copy and pasting you may loose some data if numeric values have some string characters. If you compare the missing values in the picture above (cells with dots “.”) with the excel data they are actual values but with a letter attached. If you do not need this data then do nothing. If you do, the save the file as *.csv and import it into Stata (see the “insheet” section below)
IMPORTANT: Variable names must be in the first row. Select only the data you need (do not select the entire spreadsheet)
You should see the following in the main Stata screen.
If you want to label the variables type the following.
[IMPORTANT: You may have to re-write the quotations in Stata]
label variable var1 “Area in Square Km”
label variable var2 “Area in Square Mi”
label variable var3 “Population”
label variable var4 “Imports”
label variable var5 “Exports”
label variable var6 “Type of regime”
The variables window should look like this:
Type describe for a first look:
The insheet way
This is another more systematic way of importing data into Stata.
From Excel, save the data as *.csv(comma-separated-value or comma-delimited, which is basically ASCII). The first row should have the variable names (with no spaces).
Once saved in csv format, open Stata and type in the command line
Or if you change the directory in Stata just type
insheet using cnvselect.csv
If you prefer to use the menu do the following:
In the dialog box click “Browse” then in “Files of type:” select the *.csv option and find your dataset. Once you find it click “Open” and then “Ok”.
Once you find it you should see the following, then press OK.
Your data is now in Stata format, remember to save it, type:
Type:
browse
You will see your data in the browse window
For Stata, red color means error, in this case it was expecting numeric variables but some values have letters attached so Stata reads them as string characters.
To convert those string characters into numeric you need to use destring command (type help destring for details) as follows.
Previous inspection of the variables tells us that the following characters are mixed with numeric data:
destring, replace ignore(A X W P M G R W X E Y C Q <)
In this case, the option ignore helps Stata to remove any string character attach to any number.
After using destring, use compress to convert the variables to their most efficient format.
File Extension Do Stata
How do I recover a temporary Stata file? My computer crashed when I had been working on a .do file for quite a while and I found a pretty good explanation of what temporary files are and why they are there, but no word on how to open them.
Any ideas?
Nick Coxclosed as off-topic by Pearly Spencer, Makyen, Jim Garrison, jww, Tetsuya YamamotoSep 18 '18 at 5:31
This question appears to be off-topic. The users who voted to close gave this specific reason:
- 'Questions about general computing hardware and software are off-topic for Stack Overflow unless they directly involve tools used primarily for programming. You may be able to get help on Super User.' – Makyen, Jim Garrison, jww, Tetsuya Yamamoto
2 Answers
If you type in Stata
then Stata will show you the name it has allocated for a temporary file (which does not yet exist). The important part is the filepath, which will show you where Stata stores temporary files on your system. Now it is between you and your operating system to find those files if they still exist. Whether they are as you wish them to be is a different question.
Alternatively,
will get you that information. I explain this second, because the thought process behind the first solution should be less esoteric. The puzzle is: Where does Stata put temporary files? The answer is: Create one, and see where it is on the system. (In fact, we do not need really to create one, just assign a handle.)
In fact the email you cite from Alan Riley does explain this. But the main question here is how do I recover files, and the answer does depends on what the temporary file(s) are holding. If they are text files, Stata's doedit
or any text editor will do.
But if you are expecting that Stata saves the do-file editor window contents in a temporary file of its own, independently of any tempfile
declaration made by you, and in a form that you can recover the contents, then my guess is that you will find nothing. If there is stuff, it will be in the directory or folder identified.
There is at least one possibility to recover (part of) a 'lost' do-file.
When we are writing a do-file, we usually run it along the way, just to make sure everything is going as planned. When running an unsaved do-file, Stata automatically saves it in a temporary file, found in the temp directory (@Nick has already explained how to find it). So, if you were working with a do-file, then at least the last version you executed should be there. Use any text editor to open it.
Roberto FerrerRoberto Ferrer