Stata0, Introduction - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

Stata0, Introduction

Description:

recode educ (1 2=1) (3 4=2)(missing=.), gen(educ2) From cont. to 3 groups: recode age (min/19=1) (20/29=2) (30/max=3), gen(age3) 9/8/09. H.S. 12. Labels. Variable ... – PowerPoint PPT presentation

Number of Views:22
Avg rating:3.0/5.0
Slides: 21
Provided by: heins1
Category:

less

Transcript and Presenter's Notes

Title: Stata0, Introduction


1
Stata0, Introduction
  • Hein Stigum
  • Presentation, data and programs at
  • http//folk.uio.no/heins/

2
Why Stata
  • Pro
  • Aimed at epidemiology
  • Many methods, growing
  • Graphics
  • Structured, Programmable
  • Coming soon to a course near you
  • Con
  • Memorygtfile size
  • Copy tables

3
Data handling
4
Import data
  • Using SPSS 14.0
  • Save as, Stata Version 8 SE

5
Interface
6
Do Editor
  • New
  • Ctrl-8, or
  • Run
  • Mark commands, Ctrl-D to do (execute)

7
Do-file example
8
Syntax
  • Syntax
  • bysort varlist command varlist if exp in
    range, opts
  • Examples
  • mean age
  • mean age if sex1
  • bysort sex summarize age
  • summarize age ,detail

9
Use and save data
  • Open data
  • set memory 200m
  • use C\Course\Myfile.dta, clear
  • Describe
  • describe describe all variables
  • list x1 x2 in 1/20 list obs nr 1 to 20
  • Save data
  • save C\Course\Myfile.dta ,replace

10
Drop and keep
  • Drop
  • drop x1 x2 drop variables x1 and x2
  • drop if sex1 drop males
  • drop if age. drop missing
  • Keep
  • same as drop

11
Recode
  • Syntax
  • From 4 to 2 groups
  • recode educ (1 21) (3 42)(missing.),
    gen(educ2)
  • From cont. to 3 groups
  • recode age (min/191) (20/292) (30/max3),
    gen(age3)

12
Labels
  • Variable
  • label variable q1 Age
  • Value
  • 1 ) label define freqLab 1Low 2Med 3High
  • 2a) label values smoke freqLab
  • 2b) label values drink freqLab
  • List
  • label list

13
Generate, replace
  • Age square
  • generate ageSqrage2
  • Young/Old
  • generate old0 if (agelt50)
  • replace old1 if (agegt50)
  • Observation numbers
  • gen id_n
  • gen lagage _n-1
  • Alternatives
  • generate old(agegt50)
  • generate old(agegt50) if agelt.

14
Dates
  • From numeric to date
  • ex m12, d2, y1987
  • generate bdatemdy(m,d,y)
  • format bdate d
  • From string to date
  • ex bstr01.12.1987
  • generate bdatedate(bstr,dmy)
  • format bdate d

15
Missing
  • Obs!!!
  • Missing values are large numbers
  • agegt30 will include missing.
  • agegt30 if agelt. will not.
  • Test
  • replace x0 if (x.)
  • Remove
  • drop if age.
  • Change
  • replace educ. if educ99

16
Describe missing
  • Summarize variables
  • Missing in tables

17
Handle data with many variables
  • Describe
  • describe vars format and labels
  • summarize vars N, mean, std, min and max
  • codebook vars range, missing, mean and std,
    percentiles
  • Find variables
  • describe, simple list all variables
  • lookfor age list variables with age in name or
    label
  • describe age, n list vars starting with age
    and show var number
  • Change order
  • order vars change order of variables

18
Help
  • General
  • help command
  • findit keyword search Statanet
  • Examples
  • help table
  • findit aflogit

19
Summing up
  • Use do files
  • Mark, Ctrl-D to do (execute)
  • Syntax
  • command varlist if exp in range , options
  • Missing
  • agegt30 agelt.
  • generate old(agegt50) if agelt.
  • Help
  • help describe

20
Books
  • Data Analysis Using Stata by Ulrich Kohler and
    Frauke Kreuter
  • Statistics with Stata (Updated for Version 9) by
    Lawrence C. Hamilton
  • A visual guide to Stata graphics
    by M.N. Mitchell
  • Multilevel and longitudinal modeling using Stata
    by S. Rabe-Hesketh, A. Skrondal
Write a Comment
User Comments (0)
About PowerShow.com