Professional Documents
Culture Documents
Pull-down menus
Current path
EXITING STATA
File> Exit. Alternatively, simply type exit in the Command window and press Enter.
A working directory:
File < change working directory < go to folder where data is saved.
If you are working in a computer lab, you may want to have a storage device such as a
"flash"
1
OPENING STATA DATA FILES
With Stata started, change your working directory to the where you have stored the Stata data
If you have a data file already open, and have changed it in some way, Stata will reply with
an error message. You can either save the previous data file [more on this below], or enter
The clear command will clear what is in Stata's memory. If you want to open the data file and
*dta file
Open data editor, and copy data from excel and paste into Stata.
2
Import excel file from command line:
First save your excel file into csv file then use the command
The Stata data files are stored at http://stata.com/data/s4poe. For example, to load
cps_small.dta, after saving previous data and/or clearing memory, enter in the Command
window
Use http://stata.com/data/s4poe/cps_small
Once the data are loaded onto your machine, you can save it using File> Save as and filling in
Rename variable:
3
Rename price p1
Label Variable:
The pull-down menu is Statistics > Summaries, tables, and tests > Summary and descriptive
Describe
Summarize
Help> Search
Help summarize
If you wish to summarize the data using the dialog box, enter db summarize
Syntax of summarize:
4
Summarize age, detail
Statisics > Summary statistics> Summary and descriptive statistics> Summary Statistics from
One option is to highlight the output the Results window, then right-click. then paste it into a
document. While you may be using Times New Roman font for standard text, use Courier
New for Stata output. You may have to reduce the font size to 8 or 9 to make it fit.
In addition to having results in the Results window in Stata, it is a very good idea to have all
5
summarize wage, detail
Again click on the Log Begin/Close/Suspend/Resume icon used to open the log file. In the
log using gdp, replace will open the log file and replace one by the same name if it
exists .
log using gdp, append will open an existing log file and add new results at the end.
You can print the entire log file by clicking the printer icon. Alternatively, you can highlight
parts of the smcl file and right-click. Use one of the Copy options and then paste the result
into a document.
6
To translate the *. Smcl (log file) to a text file, in the current directory, enter
If the text file already exists, and you wish to write over it, use
Print gdp.smcl
These are files containing lists of commands that will be executed as a batch.
Right-click in the Review window and then Select All. After all commands are selected
The Do-file Editor is opened. To save this file click on File> Save as.
log using gdp, replace the replace option deletes any old version of the log file.
Use consumption, clear the clear option deletes any data in memory.
7
CREATING AND MANAGING VARIABLES
Alternatively, in the Command window, enter db generate to open the dialog box.
Data> Create or change variables> Create new variable, and then click Create, opening
Expression builder.
+ addition
* multiplication
8
/ division
^ raise to a power
Sort variable:
Sort x
Ordering variables:
9
Keep deletes all variables from the data file except the ones selected.
Drop gdp
keep gdp
Drop values:
Drop in 420
Graphics> Histogram
Scatter diagrams
Scatter p1 q1
10
Fitted line scatter plot:
Pie charts:
Ttest gdp = 30
Tab var
Statistics< summaries ,. < tables < two way tables < then click on Pearsons chi2 or fisher
test.
11
Tabulate var1 var2, chi2
Statistics< summaries ,.< summary and descriptive statistics< correlation and covariances<
Regression analysis:
Predict guesq1
List q1 guesq1
predict yhat
12
predict ehat, residuals
Computing an elasticity:
Data editor> scroll down to last observation of independent variable and put value then press
Predict yhat1
Histogram ehat
Multiple regression:
13
Reg testscr str el_pct
Tsset time
predict yhat
14
construct a residual histogram:
histogram ehat
plot the fitted least squares line and the data scatter:
Statistics >linear models and related > regression diagnostics > residual vs predictor plot,
dialog box opens, select time as independent variable, click on plot and select bar, click on
y-axis and select Reference lines. Add a reference line at y = 0, click Accept and then click
ok.
Diagnostics:
predict r, resid
kdensity r, normal
15
2.3 Checking Homoscedasticity of Residuals
(predicted) values.
rvfplot, yline(0)
Breusch-Pagan test:
estat hettest
Vif
16