A Brief Introduction to Stata1 - PowerPoint PPT Presentation

1 / 30
About This Presentation
Title:

A Brief Introduction to Stata1

Description:

Start a STATA session by performing either of the following three procedures: ... This command only works if you type the full command name or keyword unabbreviated. ... – PowerPoint PPT presentation

Number of Views:78
Avg rating:3.0/5.0
Slides: 31
Provided by: zhao63
Category:

less

Transcript and Presenter's Notes

Title: A Brief Introduction to Stata1


1
A Brief Introduction to Stata(1)
2
1. Getting Started
3
  • 1.1 Starting STATA
  • 1.2 Running Stata
  • 1.3 Open and Save Datasets in Stata
  • 1.4 Exiting STATA
  • 1.5 Getting help and information
  • 1.6 Notes on STATA Commands
  • 1.7. Entering Data into STATA

4
1.1 Starting STATA
  • Start a STATA session by performing either of the
    following three procedures
  • double-click the STATA icon in your desktop.
  • find the STAR button .
  • Use Windows Explorer to navigate across the
    STATA8 folder and find the button of the
    executable file named wsestata. Double click on
    this button.

5
STATA?????
?????????
??????
????
6
STATA windows
  • Stata Command
  • Stata Results
  • Review
  • Variables

7
1.2 Running Stata
  • A command may be typed in the Stata Command
    window and executed by press the Enter key.
  • Stata running can be interrupted by holding down
    Ctrl and pressing Pause/Break key.

8
  • It is good to open a log_file, press the button
    or use .log using filename. When you want to
    close the file,use .log close.
  • Append onto the end of the current log. Type
  • .log using myses, append.
  • Discard the old log and replace it with the new
    one. Type
  • .log using myses, replace.
  • The first choice is probably the best.

9
  • You can find out what directory you're in by
    typing
  • . pwd
  • F\StataStuff
  • If you wanted to make a dirctory on the F drive
    using Stata, type
  • . cd F\
  • F\

10
Do-file
  • Do-file editor
  • Running do-file
  • Button
  • Do dofile

11
Data editor
  • Data Browser
  • Data Editor
  • Rows represent obserbvation.
  • Columns represent variables.

12
1.3 Open and Save Datasets in Stata
  • Stata has its own data format with default
    extension .dta .

13
Open a data file
  • If the file is in the current directory,
  • .Use filename
  • If the data are not stored in the current
    directory,
  • .use c\user\data
  • Or
  • .use c\user\data,clear
  • In the first form, use filename says to load the
    data, but Stata will refuse if (1) there is
    something in memory and (2) that something has
    not been saved on disk.

14
  • If the memory allocated to STATA (which is 1,000K
    or 1M by default) is too little for the data file
    to be opened we will see an error message like
    the following
  • . use hh
  • no room to add more observations
  • r(901)
  • The following commands allocate 30M to STATA and
    then tries again to open the file
  • . set memory 30m
  • . use hh
  • If you continue to get an error message, you can
    try 40m or 50m.

15
  • Another important thing to remember is that the
    memory allocation command (set memory 30m for
    example) works only if no data set is open.
    Otherwise you will get following error message
  • .use hh
  • .set memory 30m
  • no data in memory would be lost
  • r(4)
  • You can clear the memory using one of the two
    commands clear or drop _all.

16
Save a data file
  • To save, type
  • . save 1998Data
  • . save 1998Data, replace
  • . Save,replace
  • Without the replace option, the file must not
    already exist. If it does, Stata will refuse to
    overwrite it.
  • With the replace option, the file may exist or
    not. If the file does exist, it will be
    overwritten.

17
  • .cd c\user\data
  • .use bank
  • .save bank

18
1.4 Exiting STATA
  • Stata may be exited in three ways
  • Click into the Close button
  • Select the File menu from the menu bar and select
    Exit
  • Type. Exit or . exit, clear in the Stata command
    windows and press return.

19
  • if you have an unsaved data set open, STATA will
    issue the following error message
  • . exit
  • no data in memory would be lost
  • r(4)
  • To remedy this problem you can save the data file
    and then issue the exit command. If you really
    want to exit STATA without saving the data file
  • . exit, clear

20
1.5 Getting help and information
  • Stata's help system consists of two commands
  • 1) .help
  • 2) .search
  • You use help when you know the name of the Stata
    command on which you want information. This
    command only works if you type the full command
    name or keyword unabbreviated.

21
  • If you can not recall the full command name or
    keyword, or you are not sure about which command
    you want you can use the command lookup or search
    followed by the command name or keyword.
  • . search mem
  • The STATA website (http //www.stata. com) has
    excellent help facilities, for example, Online
    Tutorial, Frequently Asked Questions (FAQ), etc.

22
1.6 Notes on STATA Commands
  • STATA commands are typed in lower case.
  • All names, including commands or variable names,
    can be abbreviated as long as there is no
    ambiguity.
  • e.g.
  • .describe
  • .des

23
  • To display the previous command in Stata Command
    window, you can press Page-Up key. You can keep
    doing that until the first command of the session
    appears. Similarly, the Page-Down key displays
    the command that follows the currently displayed
    command in the Stata Command window.

24
1.7. Entering Data into STATA
  • the simplest way is to enter data directly into
    STATAs spreadsheet-like Data Editor window.
  • The nineth button
  • . edit
  • Note that data from spreadsheets can also be
    copied and pasted into the Editor.

25
  • you can entering data variable-by-variable with
    the TAB key or observation-by-observation with
    the ENTER key.
  • a missing value is coded as a period .
  • numerical values should not include commas
    otherwise STATA considered these values as
    string.

26
  • string variable values can nearly be almost any
    combination of letters, numbers, and symbols up
    to 80 characters in length for Intercooled/ Small
    and up to 244 characters in length for STATA/SE.
  • http//www.ats.ucla.edu/stat/stata/how_to_get_stat
    a.htm
  • variable names can be changed by double clicking
    anywhere in the variables column resulting in a
    dialogue box. It is suggested that variable
    names should have 8 characters.

27
Reading different types of datafile
  • Using Stata transfer
  • Other ways
  • read data into STATA from ASCII files and
    worksheets, We can use the infile command
  • . cd c\intropov\data
  • . infile domain hcn age using try.txt

28
  • use the infix command
  • . clear
  • . infix domain 1 hcn 2 age 3-4 using try2.txt
  • Excel worksheets such as the .xls file can also
    be read into STATA. However, we have to first
    read the file with Excel, and convert the file
    into a comma-delimited file, i.e., click on File,
    Save AS, and choose as file type CSV. Then,
    enter
  • . insheet using filename.csv, clear

29
Review
  • Ctrl Pause/Break
  • .log using myses, append
  • . pwd
  • . cd F\
  • use c\user\data,clear
  • set memory 30m
  • . save 1998Data, replace
  • . Save,replace

30
  • . exit
  • .help
  • .search
  • .describe
  • .des
  • .edit
  • .infile
  • .infix
  • .insheet
Write a Comment
User Comments (0)
About PowerShow.com