Download presentation
Presentation is loading. Please wait.
1
Presentation, data and programs at:
Stata0, Introduction Hein Stigum Presentation, data and programs at:
2
Why Stata Pro Con Aimed at epidemiology Many methods, growing Graphics
Structured, Programmable Coming soon to a course near you Con Memory>file size Copy tables Time: 1 h 15 min Used by leading univ, and at many summer schools Apr-19 H.S.
3
Data handling
4
Import data Using SPSS 14.0 Save as, Stata Version 8 SE Apr-19 H.S.
New version of DBMSCopy support lonf variable names Apr-19 H.S.
5
Interface Apr-19 H.S.
6
Do Editor New Run Ctrl-8, or: Mark commands, Ctrl-D to do (execute)
Open do file Copy commands Copy review to clipboard Run commands Apr-19 H.S.
7
Do-file example Apr-19 H.S.
8
Syntax Syntax Examples
[bysort varlist:] command [varlist] [if exp] [in range][, opts] Examples mean age mean age if sex==1 bysort sex: summarize age summarize age ,detail All commands same Some simple and some advanced options (and prefixes) Apr-19 H.S.
9
Use and save data Open data Describe Save 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 Default memory=10m Have we seen in 1/20 before? Apr-19 H.S.
10
Drop and keep Drop Keep drop x1 x2 drop variables x1 and x2
drop if sex==1 drop males drop if age==. drop missing Keep same as drop Drop var =columns Drop obs =lines Apr-19 H.S.
11
Recode Syntax From 4 to 2 groups:
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) Auto: 3 equal sized groups with labels at() values outside set to missing String destring stringvar, generate(newvar) force force specifies that any string values containing non-numeric characters be treated as indicating missing numeric values. Apr-19 H.S.
12
Labels Variable Value List label variable q1 ”Age”
1 ) label define freqLab 1”Low” 2”Med” 3”High” 2a) label values smoke freqLab 2b) label values drink freqLab List label list Label list: show all variables with their labels Names and labels are used in plots: define good english names May also add information in labels (N=230) Add numeric coding to labels: numlab, add/remove Apr-19 H.S.
13
Generate, replace Age square Young/Old Alternatives
generate ageSqr=age^2 Young/Old generate old=0 if (age<=50) replace old=1 if (age>50) Observation numbers gen id=_n gen lag=age[ _n-1] Alternatives generate old=(age>50) generate old=(age>50) if age<. Missing defined in next slide Apr-19 H.S.
14
Dates From numeric to date From string to date ex: m=12, d=2, y=1987
generate bdate=mdy(m,d,y) format bdate %d From string to date ex: bstr=“ ” generate bdate=date(bstr,”dmy”) Apr-19 H.S.
15
Missing Obs!!! Test Remove Change Missing values are large numbers
age>30 will include missing. age>30 if age<. will not. Test replace x=0 if (x==.) Remove drop if age==. Change replace educ=. if educ==99 gen age2=(age>30) if age!=. Also .a .b .c … Apr-19 H.S.
16
Describe missing Summarize variables Missing in tables Apr-19 H.S.
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 Apr-19 H.S.
18
Help General Examples help command findit keyword search Stata+net
help table findit aflogit findit key=search key,all rc=return code Apr-19 H.S.
19
Summing up Use do files Syntax Missing Help
Mark, Ctrl-D to do (execute) Syntax command [varlist] [if exp] [in range] [, options] Missing age>30 & age<. generate old=(age>50) if age<. Help help describe Apr-19 H.S.
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 Apr-19 H.S.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.