Introduction To Stata and Data Management
Introduction To Stata and Data Management
A. STATA windows
- Review
- Results
- Variables
- Command
B. Stata Toolbar
- It has different functioning buttons
C. Stata Log File
D. Stata‘s Help Future
INPUTING DATA INTO STATA USING THE DATA
EDITOR
Click on the Data Editor button or type edit in the command window and
press return
A. Inputting Data
Things to know about entering data in Stata
B. Renaming Variables
Click on the variable manager button. This brings up the Variable
Information dialog box. Enter the new name of the variable and specify a
more detailed description of the variable.
Rules for variable names:
• Stata is case sensitive
• A variable name must be between 1 and 32 characters long
• Characters can be letters, digits, or underscores
• Spaces or other characters are not allowed
• The first character of a variable name must be a letter or an
underscore
INPUTING DATA CONT…
2. String
storage Maximum
type length Bytes
----------------------------------
str1 1 1
str2 2 2
... . .
str244 244 244
----------------------------------
DATA FORMAT
Storage types: tells the number of digits of accuracy (in other words how many storage
bites they accomodate.
byte %8.0g /* g refers to general & f refers to fixed, other types exist for binary,
exponential etc*/
int %8.0g
long %12.0g /*9 digits of accuracy*/ & /* 0 decimal levels*/
float %9.0g /* 8 digits of accuracy*/
double %10.0g /* 16 digits of accuracy*/
str# %#s (string fromat) eg. Str4 %4s (indicates the maximum length of the
string is 4)
To get the format type, use command
format race
To change string form in to numeric/real, use the command
destring race, replace
LISTING DATA
A. List
Typing list in the Command Window lists the entire data set. A subset of
variables can be listed.
B. List with in
The Stata command in restricts the list to a range of observations
Positive numbers count from the top of the data. Negative numbers count from
the end of the data
You can specify both a variable range and an observation range.
Example:
Type the following commands in the Command
– tab _merge
Here are the codes for _merge:
Centiles (percentiles)
Centile science
Centile science, centile(50) normal
Centile science, centile(10(10)100) normal
Centile science, centile(20(20)100) normal
STORING COMMANDS AND OUTPUTS
How to save our results in word/excel?
Word
Just copy from the result window and paste it then select it in word and
change the font style in to courier new (in case bigger adjust fontsize).
Excel
Just copy the results, paste it in stata. Then select the first column, go to
data then choose text to columns, next, next, finish.
How to save reg results in memory, see out & copy in Excel?
outreg2 using myfile, dec(2)
outreg2 using myfile, dec(2) replace
outreg2 using myfile, bdec(2) sdec(2) replace
outreg2 using myfile, word excel replace
USING DO-FILE EDITOR
Using the Stata Do-File editor: This editor works like most text editors; use
help to get more details. After you enter your program, click the do-current-file
icon do the file. When you do the file, the results are sent to the Stata Results
window and the log file. Click the run-current-file icon to run the commands,
without sending them to the Stata Results window.
Structure of a Do File: Here is an example of what you want to put in a do
file. Note that anything following a * is not executed but is printed.
- capture log close/cap log close/log close: This command closes any open .log
file. If no log file is open, STATA just ignores this command.
set mem 40m
set more off