Escolar Documentos
Profissional Documentos
Cultura Documentos
InformationtousersofStata8to12
AnIntroductiontoStataforHealthResearchers,firstedition1waswrittenforStatarelease9,the
secondedition2waswrittenforStata10;andthethirdedition3forStata11.Thethirdeditionisalso,
withfewexceptions,validforStata12,andwearenotcurrentlyplanningafourthedition.Wereferto
thedifferenteditionsofthebookasISHR1,ISHR2,andISHR3.
TheremaybesomediscrepanciesbetweenyoureditionoftheISHRbookandthereleaseofyour
Stataprogram,andinthefollowingwepointtothemostimportantchanges,organizedbythe
structureofthebook.Weareonlypointing,andyouwillprobablyneedtouseStata'shelpfacilitiesto
getmoreinformation.WestronglyrecommendtokeepyourStataprogramupdatedtothelatest
version;Stata11,forexample,toversion11.2.
Toseeallchanges,forexamplefromrelease11to12,type:
.helpwhatsnew11to12
Stataintroducednewfileformatsinreleases8,10,and12.YourStataprogramreadsdatasetsfrom
previousreleaseswithouttrouble,buttheoppositeisnotthecase.45Ifyouwanttocreateadataset
thatcanbereadbyapreviousStataversion,youmayneedtousethesaveoldcommand;seethe
followingtable.
YourversionofStata:
savegeneratesdata
withtheformatof:
saveoldgeneratesdata
withtheformatof:
Stata12
Stata12
Stata8/9
Stata10or11
Stata10/11
Stata8/9
Stata8or9
Stata8/9
Stata7
SomedatefunctionsandformatschangedfromStata9toStata10.WithStata10to12,youcanstill
usetheStata9syntaxusingversioncontrol:
.version9:generatebdate=date(sbdate,"dmy")
SvendJuul,MortenFrydenberg,August2011
JuulS.AnIntroductiontoStataforHealthResearchers.CollegeStation,TX:StataPress,2006
JuulS.AnIntroductiontoStataforHealthResearchers.2nded.CollegeStation,TX:StataPress,2008.
JuulS,FrydenbergM.AnIntroductiontoStataforHealthResearchers.3rded.CollegeStation,TX:StataPress,2010.
AnupdatetoStata11willallowStata11toreadStata12datasets.TheupdateisexpectedinSeptember2011,soStata
11usersshouldstillupdateregularly.
Stata9users:Theunofficialuse10commandreadsStata10/11datasets.Getifbysscinstalluse10.
ChangesfromStata11toStata12
TheinformationisorganizedbythechaptersinISHR3.IntheStata12columnweshowchangesfrom
thedescriptioninISHR3.
Section Stata12
Stata11(asdescribedinISHR3)
1.4
Differentorganizationofwindows,including
anewPropertieswindow.Thedefaultlayout
fitsawidescreen;ifyoupreferanarrower
layout,select:
Edit>Preferences>LoadPreferenceSet>
CombinedLayout
1.4
PasteavariablenamefromtheVariables
windowtotheCommandwindowwitha
doubleclick.
PasteavariablenamefromtheVariables
windowtotheCommandwindowwitha
singleclick.
1.4
Improveddataeditor.IntheVariables
Windowyoucandoquiteafewthings,
includinghidingandreorderingvariables.
5.8
Stata12automaticallycalculatesthememory setmemoryallocatesStatamemory.
needs,andthesetmemorycommandisno
longerneeded.
6.4
Stata12nowimportsandexportsExceland
SASdatadirectly.See:
helpimportexcel
helpimportsas
ImportandexportSASdatasetsusingthe
fdauseandfdasavecommands.
9.2
New,flexiblerenamegroupcommand.See:
helprenamegroup
13.3
Thecontrastcommandmaybeusedasa
handyreplacementfortestparm.See:
helpcontrast
13.3
Theoutputfromregressioncommands
(includinglogistic,stcox,andpoisson)with
factorvariableswillalwaysdisplaythebase
levelifyou,justonce,givethecommand:
setshowbaselevelson,permanently
andwerecommenddoingthattoenhance
transparency.
Bydefault,baselevelsareomittedfromthe
output.
Thesetshowbaselevelsfacilitywas
introducedinStata11.1,June2010.
13.5
14.7
Baselineestimates(baselineodds,risk,rate)
aredisplayedbyeformcommands,like:
logisticandlogit,or
binreg,rr
poisson,irr
Baselineodds,risk,andrateestimatesare
notdisplayedbylogisticoranyothereform
command.
17.12
YoucanexportagraphtoaPDFfile.See:
helpgraphexport
ChangesfromStata10toStata11
TheinformationisorganizedbythechaptersinISHR2.IntheStata11columnweshowchangesfrom
thedescriptioninISHR2.
Section Stata11
Stata10(asdescribedinISHR2)
1.4
DataEditor/Browserimproved.Youneednot DataEditor/Browsermustbeclosedwhile
closeitwhiledoingotherthingsinStata
doingotherthingsinStata
1.4
DofileEditorimproved.Itnowhassyntax
highlighting
1.5
NewVariablesManager
2.2
PDFversionofmanualsincluded
Onlyprintedversionofmanuals
5.3
Newmisstablecommanddescribesmissing
valuepatterns.
Newmifamilyofcommandsperforms
multipleimputationofmissingvalues.
9.3
Ordervariablesalphabeticallyby:
ordervarlist,alphabetic
Ordervariablesalphabeticallyby:
aorder
9.5
Newmergesyntax,e.g.:
usefilea.dta
merge1:1idusingfileb.dta
mergeautomaticallysortsthedatasets.
Theoldmergesyntaxstillworks.
Oldmergesyntax,e.g.:
usefilea.dta
mergeidusingfileb.dta
Thedatasetsmustbesortedbythematching
keybeforemerging
13.1
FactorvariablesisanewconstructinStata
11;itpartiallyreplacesthexi:prefixin
regressioncommandsbutxi:stillworks.
Seeshortdescriptionnextpages.
Usethexi:prefixforcategoricalvariablesand
interactionsinregressionanalyses.
13.3
Stata11.1andlater(June2010):
Theoutputfromregressioncommands
(includinglogistic,stcox,andpoisson)with
factorvariableswillalwaysdisplaythebase
levelifyou,justonce,givethecommand:
setshowbaselevelson,permanently
andwerecommenddoingthattoenhance
transparency.
Bydefault,baselevelsareomittedfromthe
output.
14.3
Youneednotspecifytheschoenfeld()and
basesurv()optionstostcoxtousetheestat
phtestandstcurvepostestimation
commands.
Youmustspecifytheschoenfeld()and
basesurv()optionstostcoxtousetheestat
phtestandstcurvepostestimation
commands.
16.1
Newrandomnumberfunctionnames:
runiform()
rnormal()
CorrespondingStata10functions:
uniform()
invnormal(uniform())
Factorvariables:NewconceptinStata11.
Weusethelbw1.dtadataset:
. cd c:\docs\ishr3
. use lbw1.dta
. list race i.race in 1/3
+-------------------------------+
|
1b.
2.
3.|
|
race
race
race
race |
|-------------------------------|
1. | 2. black
0
1
0 |
2. | 3. other
0
0
1 |
3. | 1. white
0
0
0 |
+-------------------------------+
i.racerepresentsthreevirtual0/1variables.1b.race,2.race,and3.racedonotreallyexistinthe
dataset,butwithsomecommands,likelist,theyseemtoexist.Notethatracemusttakenonnegative
integervaluesonly;factorvariablesdonotworkwithnonintegercodes.
Inregressionanalyses,etc.,theycanbeusedasindicator(dummy)variables;itgoeslikethis:
Source |
SS
df
MS
-------------+-----------------------------Model | 12346897.6
3 4115632.54
Residual | 87568400.9
185 473342.708
-------------+-----------------------------Total | 99915298.6
188 531464.354
Number of obs
F( 3,
185)
Prob > F
R-squared
Adj R-squared
Root MSE
=
=
=
=
=
=
189
8.69
0.0000
0.1236
0.1094
688
-----------------------------------------------------------------------------bwt |
Coef.
Std. Err.
t
P>|t|
[95% Conf. Interval]
-------------+---------------------------------------------------------------race |
1 | (base)
2 |
-450.54
153.066
-2.94
0.004
-752.5194
-148.5607
3 | -454.1813
116.436
-3.90
0.000
-683.8944
-224.4683
|
smoke |
0 | (base)
1 | -428.0254
109.0033
-3.93
0.000
-643.0746
-212.9761
|
_cons |
3334.858
91.74301
36.35
0.000
3153.86
3515.855
------------------------------------------------------------------------------
Theoutputdisplaysthebaselevels,1forraceand0forsmoke.6Withthei.prefix,Stataselectsthe
lowestvaluesasthebaselevel.Weprefer,however,tocontrolthebaselevelsdirectly;thiscanbe
donewith,e.g.,theb2.prefix:
Fromversion11.1ofStata,youcan,onceandforall,givethecommand
.setshowbaselevelon,permanently
Thentheregressionoutputwillshowthebaselevelsdirectly,asintheexampleshere.
Number of obs
F( 3,
185)
Prob > F
R-squared
Adj R-squared
Root MSE
=
=
=
=
=
=
189
8.69
0.0000
0.1236
0.1094
688
-----------------------------------------------------------------------------bwt |
Coef.
Std. Err.
t
P>|t|
[95% Conf. Interval]
-------------+---------------------------------------------------------------race |
1 |
450.54
153.066
2.94
0.004
148.5607
752.5194
2 | (base)
3 | -3.641269
160.537
-0.02
0.982
-320.3599
313.0773
|
smoke |
0 | (base)
1 | -428.0254
109.0033
-3.93
0.000
-643.0746
-212.9761
|
_cons |
2884.317
141.291
20.41
0.000
2605.569
3163.066
------------------------------------------------------------------------------
Wewanttoincludeaninteractionbetweenraceandsmoke;itisdonewiththetermi.race##i.smoke,
or,tocontrolthebaselevelsexplicitly,byb1.race##b0.smoke.Hadweusedasinglecross,
b1.race#b0.smoke,theregressionwouldcomparefiverace/smokegroupswithwhitenonsmokers.
Source |
SS
df
MS
-------------+-----------------------------Model | 14455540.4
5 2891108.08
Residual | 85459758.2
183 466993.214
-------------+-----------------------------Total | 99915298.6
188 531464.354
Number of obs
F( 5,
183)
Prob > F
R-squared
Adj R-squared
Root MSE
=
=
=
=
=
=
189
6.19
0.0000
0.1447
0.1213
683.37
-----------------------------------------------------------------------------bwt |
Coef.
Std. Err.
t
P>|t|
[95% Conf. Interval]
-------------+---------------------------------------------------------------race |
1 | (base)
2 |
-574.25
199.5008
-2.88
0.004
-967.8674
-180.6326
3 | -614.5136
138.2182
-4.45
0.000
-887.2198
-341.8075
|
smoke |
0 | (base)
1 | -601.3654
139.979
-4.30
0.000
-877.5456
-325.1851
|
race#smoke |
2 1 |
250.8654
308.9992
0.81
0.418
-358.7938
860.5245
3 1 |
544.2957
258.8455
2.10
0.037
33.59038
1055.001
|
_cons |
3428.75
103.0218
33.28
0.000
3225.487
3632.013
------------------------------------------------------------------------------
ChangesfromStata9toStata10
TheinformationisorganizedbythechaptersinISHR1.IntheStata10columnweshowchangesfrom
thedescriptioninISHR1.
Section Stata10
Stata9(asdescribedinISHR1)
1.4
Selectwindowingpreferencesby:
Edit>Preferences>ManagePreferences>
Selectwindowingpreferencesby:
Prefs>ManagePreferences>
1.4
Savepastcommandstoadofilebyclicking
somewhereintheReviewwindow.PressCtrl
AtohighlightallcommandsandCtrlCto
copythemtotheWindowsClipboard.Next
openaDofileEditorwindowandpastethe
commandsbypressingCtrlV.
Helpfilesnowhavetheextension.sthlp(but Helpfileshavethe.hlpextension.
Stata10stillunderstandsthe.hlpextension)
5.5
NewinStata10:Dateandtimevariables
withnewformatdescriptors(oldformat
descriptorsstillwork).
Stata9hasdatevariables,butnofacilitiesfor
handlingtimeofday.(Someunofficial
commandsandfunctionsmaybehelpful).
5.5
Inthedate()functionthesequencecanbe
definedas"DMY".
(YoucanusetheStata9"dmy"specification
withversioncontrol;seepage1).
Inthedate()functionthesequencecanbe
definedas"dmy".
6.1
savesavesadatasetinStata10/11format;it
cannotbereadbyStata8or9.Tocreatea
datasetthatcanbereadbyStata8/9,usethe
saveoldcommand
ToenableStata9toreadadatasetcreated
byStata10/11'ssavecommand,installthe
unofficialuse10commandby:
sscinstalluse10
6.4
Stat/Transfer9translatesStata10/11files,
butStat/Transfer8doesnot.
11.10
Newgrapheditor.
13.3
Newexlogisticcommandforexactlogistic
regression
14.2
Newrisktableoptiontostsgraphdisplays
numberatriskbelowthexaxis.
14.5
NewexpoissoncommandforexactPoisson
regression
16.2
Newstpowercommand(samplesizeand
powerforincidenceandsurvivalanalysis)
17.4
Tocreater(varlist):
describe...,varlist
Tocreater(varlist):
describe...,simple
18.7
Newdatasignaturecommand.
ThedatasignaturecommandinStata9.2is
differentfromtheversion10command.
ChangesfromStata8toStata9
TheinformationisorganizedbythechaptersinISHR1.
Section Stata9(asdescribedinISHR1)
Stata8
1.4
YoucanhavemultipleDofile,Viewer,and
graphwindows.
YoucanhaveonlyoneDofileeditorwindow,
oneViewerWindow,andoneGraphwindow
1.4
Datawindow:Stringvariablesaredisplayed
inred,valuelabelsinblue.Youmaytoggle
betweendisplayingvaluelabelsandcodes.
Novisualdistinctionbetweenstringvariables
andvaluelabels.TheDatawindowdisplays
valuelabels,unlessyouopenitby:
browse,nolabel
2.1
NewDatamanagementmanual,[D].
Datamanagementcommandsin[R].
2.3
NewcommandinStata9.1:
adoupdate
6.4
NewcommandsinStata9:
xmlsave
xmluse
8.2
Newfunctionnames(theoldnamesstillwork
inStata9,butnotinStata10):
normal()
invnormal()
normalden()
Oldfunctionnames:
norm()
invnorm()
normden()
8.3
New,lessconfusingegenfunctionnames(the
oldnamesstillwork):
total()
rowmin()
rowmax()
rowtotal()
rowmiss()
rownonmiss()
Oldfunctionnames:
sum()
rmin()
rmax()
rsum()
rmiss()
robs()
9.5
Newsortoptiontomerge.
10.1
Newoptiontocodebook:
codebook,compact
Nocompactoptiontocodebook.Auseful
alternativeistheunofficialsummvl:
finditsummvl
10.3
NewcommandinStata9:
proportion
10.4
NewcommandinStata9:
mean
11.7
Markerandlineoptionssimplified(theold
optionnamesstillwork)
SeeStata8syntaxintablebelow
13
stepwise
sw
Section Stata9
Stata8
13.2
estatgof
13.4
svy:
Surveyanalysiscommandschangedsyntaxin
version9.
14.3
estatphtest
17.1
statsby:
Changedsyntax
17.3
Newfunctionname(theoldnamestillworks
inStata9,butnotinStata10):
strpos()
lfit
stphtest
Oldfunctionname:
index()
Stata8:Optionsfordefiningtheappearanceoflines,barsandmarkers
(theyaremuchsimplerinStata9;seeISHR1table11.2):
Lines
Markers
Element
Color
Pattern
Width
Symbol
Size
Legendetc.
color()
fill
fcolor()
outline
lcolor()
lpattern()
lwidth()
Bars,areas
bcolor()
fill
bfcolor()
outline
blcolor()
blpattern()
blwidth()
Markers
mcolor()
msymbol()
msize()
fill
mfcolor()
outline
mlcolor()
mlwidth()
clpattern()
clwidth()
Connectinglines clcolor()