49
ukdataservice.ac.uk What is Stata?

What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

Embed Size (px)

Citation preview

Page 1: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

ukdataservice.ac.uk

What is Stata?

Page 2: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress
Page 3: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress
Page 5: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

. set memory 20m, permanently

. set mem 20m, perm

. use <filename>, clear

Page 6: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

<filename>

. cd C:\Data_Stata

use <filename>

Page 7: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress
Page 8: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

. lookfor hours

. describe

. clear

. rename var1 = id

. label var id “identification no.”

. renvars v*\id sex age income

. compress

Page 9: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

. describe numchild04

. de numchild04

Page 10: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

. codebook ten1

. help describe

. findit describe

Page 11: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

. save <filename>

. save, replace

Page 12: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

. log using <filename>

<filename>

<filename> <filename>

<filename>.

. log off

. log on

. log close

. tabulate sexx

Page 13: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

. ta sexx

. tabulate sexx, nolabel

. tab1 sexx marcivx fbx

Page 14: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

. codebook jobtyp

. tabulate jobtyp, missing

Page 15: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

. mvdecode <variable>, mv(<value>)

. mvdecode jobtyp, mv(-8, -9)

. mvdecode jobtyp, mv(-8=.a \ -9=.b)

. mvdecode _all, mv(-8=.a \ -9=.b)

mvencode

. mvencode _all, mv(.a=-8 \ .b=-9)

. tab marcivx sexx, r m

Page 16: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

tab2

. tab2 marcivx fbx sexx, r m

Page 17: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

. tab2 marcivx sexx, chi2

. table marcivx fbx sexx

. sum hourpay

. sum hourpay, detail

Page 18: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

. sum hourpay if sexx==1, detail

Page 19: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

. ta marcivx sexx if (statusx==1& hourpay>0), su(hourpay) means

. bysort ages: tabulate marcivx sexx if (statusx==1&hourpay>0), su(hourpay) means

nofreq

Page 20: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress
Page 21: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

. ta sexx marcivx [fweight=pwt11]

. ta sexx marcivx [fw=pwt11]

. table marcivx sexx if (statusx==1&hourpay>0), c(mean hourpay) format(%9.2f)

Page 22: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

. ta sexx marcivx [w=pwt11]

. help weight

Page 23: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

. generate sex1=sexx

. label variable sex1 “sex of respondent”

. label define sexlabel 0 male 1 female

. label values sex1 sexlabel

label define

. gen sex2=sexx

. label values sex2 sexlabel

. rename sex2 sex3

Page 24: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

. gen agesquared=age^2

. gen weekpay=hourpay*35

. gen age40_a=age >=40 if age ~=.

. gen age40_b=cond(age >=40, 1,0) if age ~=.

. tab age40_a age40_b

. gen age40=1 if age >=40

. replace age40=0 if age40 ~=1 & age ~=.

. help reswords

. help _variables

Page 25: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

. label define AGEG40 1 “Aged 40 or older” 0 “Less than 40”

. label values age40 AGEG40

. codebook ethukeul

. gen white = ethukeul

. recode white 1=1 2/9=0 *=.

. label variable white "White versus non-white"

. replace varx=1 if varz>4000

. replace varx =1 if varz > 4000 & varz ~= .

Page 26: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

. label define WHITE 1 "White" 0 "Non-white"

. label values white WHITE

. tab eth white

. codebook age

. gen agegroup=age

. recode agegroup min/19=1 20/29=2 30/39=3 40/49=4 50/59=5 60/65=6 *=.

. label variable agegroup "age in 10-year groups"

. label define AGEGGROUP 1 "16-19yrs" 2 "20-29yrs" 3 "30-39yrs" 4 “40-

49yrs” 5 “50-59yrs” 6 “60-69yrs”

. label values agegroup AGEGGROUP

. tab age agegroup

. recode ethukeul 1=1 2/9=0 *=., generate(white)

Page 28: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress
Page 29: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

. histogram hourpay

. histogram hourpay if hourpay >0 & hourpay <200 [fw=pwt11], bin(30) percent

scheme(s2color) title(Hourly pay (pounds))

. help histogram

Page 30: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

. twoway scatter hourpay

. twoway (scatter hourpay age if hourpay>0 & hourpay<=200), title(Women's

hourly pay (pounds) by age) subtitle (hourly pay>0 and <= 200 pounds)

note("Source: Labour Force Survey, October-December 2012.”)

. help graph

Page 32: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

use <filename>, clear

set more off

sum hourpay if hourpay>0

tab sexx if hourpay>0, sum(hourpay)

end of do-file

Page 33: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress
Page 34: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress
Page 36: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

. tab sex ten1 if hrp==1, col

. keep if hrp==1

. save <newfilename>

. tab hrp

Page 37: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

. sort aacode

. collapse (max) oldest=age, by(aacode)

. save <newfilename2>

. sort aacode

. egen oldest = max(age), by(hserial)

. bysort hserial: egen oldest = max(age)

. sort aacode

. merge 1:m aacode using <other file>

. sort aacode

. merge aacode using <householdfile.dta>

Page 38: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

. ta _merge

Page 39: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

. use <interviewfs11.dta>, clear

. sort aacode

. save <interviewfs11.dta>, replace

. clear

. use <generalfs11.dta>, clear

. sort aacode

. save <generalfs11.dta>, replace

. joinby aacode using <interviewfs11.dta>

. save <household11.dta>, replace

Page 40: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

. use <generalfs10.dta>, clear

. ge year= 2010

. save <year10>, replace

. clear

Page 41: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

. use <generalfs11.dta>, clear

. ge year= 2011

. save year11, replace

. append using year10

. save years1011, replace

. sort year

. duplicates report aacode

. duplicates report aacode year

Page 42: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

. help estimation commands

. help estcom

. regress depvar [varlist] [weight] [if exp] [in range] [, level(#) beta robust

noconstant noheader]

. help regress

Page 43: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

. char ethukeul [omit]1

Page 44: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

. xi: regress grsswk i.ethukeul if statusx==1 & grsswk~=.

. est store model1

. xi: regress grsswk i.eth i.sexx i.marcivx if status==1& grsswk~=.

Page 45: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

. est store model2

. xi: regress grsswk i.eth sexx marc if status==1& grsswk~=.

. est query

. est dir

Page 46: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

. est replay model1

. est restore model1

. est table model1 model2, star eform

. testparm _Is* _Ima*

Page 47: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

. test _Iethukeul_3=_Iethukeul_4

. test _Iethukeul_3=_Iethukeul_5

. help testparm

. help test

. help logit postestimation

. help postestimation commands

Page 48: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

. help postest

. help y_41

Page 49: What is Stata? - UK Data Service · . lookfor hours . describe . clear . rename var1 = id. label var id “identification no.”. renvars v*\id sex age incomecompress

16 May 2014

T +44 (0) 1206 872143E [email protected] ukdataservice.ac.uk

The UK Data Service delivers quality social and economic data resources for researchers, teachers and policymakers.

© Copyright 2014 University of Essex and University of Manchester