0.1 Intro To Stata
0.1 Intro To Stata
Introduction
Jairos Sambo, MA
March 4, 2019
Lusaka, Zambia
1
STATA: History of STATA
• Program was developed for the IBM PC and the DOS operating system in 1984
by Bill Gould and Sean Becketti
• First version focused mainly on regression but had data management functions
• Over the years has developed strong user input through forums
– Include discussions about STATA
– Writing and sharing of STATA programs
– Led to the development of Statistical Software Components (SSC) archive - a
searchable database of user-written STATA programs
• STATA version 8 was the biggest rewrite of the program
– Had a new interface
– Included new graphics
• Current version of STATA is 18
• Advantages of STATA (over its main competitors SAS and SPSS)
– Cutting-edge statistical procedures
– Small, fast and available for various processors
– Reasonably priced with lifetime license
2
STATA file naming scheme
• *.dta (STATA data files)
• *.do (STATA instruction file. Contains set of
commands for processing STATA data files
and setting-up the STATA environment)
• *.log (This is the output file. Contains all that
is in the output window)
– Activated by issuing the command: log using
filename.log
– Terminated by issuing the command: log close
3
The STATA Menu System
• STATA can be started from the desktop or
program files
Double clicking the icon on the Desktop
Start All Programs STATA
4
5
Basic STATA windows. There are 5 basic windows when STATA is
started:
6
Basic STATA windows. There are 5 basic windows when STATA is
started:
7
Basic STATA windows. There are 5 basic windows when STATA is
started:
8
Basic STATA windows. There are 5 basic windows when STATA is
started:
9
Basic STATA windows. There are 5 basic windows when STATA is
started:
10
STATA Organisation and Window System
• Basic STATA windows. There are 5 basic windows when STATA is started:
– The Command Window
• This is where commands are entered interactively
• Do-files executed here
– The Results Window
• Show commands executed and results of commands
• Shows commands executed from the MENU
• Shows logs (errors, warnings etc.)
– The Review Window
• Shows list of commands executed from the Command Window AND Menu
– The Variables Window
• Shows variables and properties of variables of the active data set
– The Properties Window:
• Shows details on the composition of the variable selected and the dataset as a whole.
– There are other STATA windows that are activated for a number of procedures and activities.
For example:
• Graphs
• Browse
11
Basic STATA windows. There are 5 basic windows when STATA is
started:
12
Basic STATA windows. There are 5 basic windows when STATA is
started:
13
Basic STATA Commands - Navigation
• Exercise: Look at the names of the files in the folder and try to
match these names with sections of the questionnaire
14
Basic STATA Commands: Using a Data File
16
Preliminary View of Data - describe
17
Preliminary View of Data - list
18
Preliminary View of Data - list
19
Preliminary View of Data - list
– Exercise. Try:
• list prov dist cluster HH in 1/50 if cluster < 1040
• Explain the output
20
Preliminary View of Data – browse
21
Preliminary View of Data – browse
22
Preliminary View of Data – count
23
Preliminary View of Data – sort
24
Preliminary View of Data – gsort
25
One more thing...
• Change the path (directory) to the stata data file: " “C:\
Users\Jairos Sambo\Desktop\STATA TRAINING\
data_rals\stata”
• Open : livestock.dta
• Determine the total sample size using the ‘count’
command.
• Determine the sample size in each province using the
‘count’ and ‘if’ commands.
• Sort the dataset in order of farmer category.
• Browse the sorted data to confirm it is correct.
28
EXERCISE 2
29
Thank You
30