Docsity

Stata Document: Simple Linear Regression in Intermediate Biostatistics - Prof. Carol Bigel, Study notes of Community Health

Toggle sidebar
bg1
PubHlth 640 โ€“ Intermediate Biostatistics Simple Linear Regression Stata v 10
Stata v 10 Illustration
Simple Linear Regression
Before you begin:
(1) Comments begin with an asterisk and are in red
(2) Stata commands are typed in blue
(3) User specifications are typed in green
* Begin your STATA session by opening a log of your session
------------------------------------------------------------------------ ------------------------
log: /Users/carolbigelow/Desktop/week2_2009.log
log type: text
opened on: 8 Feb 2009, 17:43:40
. * The command SET MORE OFF will prevent pauses in results screen by screen
. set more off
Z:\bigelow\....\web640\stata\week2_2009.doc Page 1 of 8
pf3
pf4
pf5
pf8

Partial preview of the text

Download Stata Document: Simple Linear Regression in Intermediate Biostatistics - Prof. Carol Bigel and more Study notes Community Health in PDF only on Docsity!

Stata v 10 Illustration

Simple Linear Regression

Before you begin: (1) Comments begin with an asterisk and are in red (2) Stata commands are typed in blue (3) User specifications are typed in green

  • Begin your STATA session by opening a log of your session

log: /Users/carolbigelow/Desktop/week2_2009.log log type: text opened on: 8 Feb 2009, 17:43:

. * The command SET MORE OFF will prevent pauses in results screen by screen . set more off

. * Import into STATA the data to be analyzed . use "/Users/carolbigelow/Desktop/1. Teaching/web640/data sets/week02.dta" . * Produce a list of the variable names and storage type using DESCRIBE . describe

Contains data from /Users/carolbigelow/Desktop/1. Teaching/web640/data sets/week02.dta obs: 31 vars: 2 size: 372 (99.9% of memory free)


storage display value variable name type format label variable label


temp float %9.0g boiling float %9.0g


Sorted by:

. * Create the variable NEWY using the command GENERATE . generate newy=100log10(boiling) . * Label the variables using the command LABEL VARIABLE . label variable temp "TEMP: Temperature" . label variable newy "NEWY: 100log10(Boiling)" . label variable boiling "BOILING: Y"

. * Obtain detailed statistics using SUMMARIZE with option DETAIL . summarize boiling, detail

BOILING: Y

Percentiles Smallest 1% 12.267 12. 5% 15.376 15. 10% 15.928 15.919 Obs 31 25% 16.817 15.928 Sum of Wgt. 31

50% 19.386 Mean 19. Largest Std. Dev. 4. 75% 21.892 24. 90% 24.697 27.972 Variance 16. 95% 28.559 28.559 Skewness. 99% 29.211 29.211 Kurtosis 3.

. *Obtain histogram of distribution of Y=Boiling . histogram boiling (bin=5, start=12.267, width=3.3888) . * save graph as week2_2009_1.png . * Activate the graph by clicking on it . *Click on the icon that looks like a disk . * At FORMAT drop down menu: Choose "portable network graphic (.png)" . * At SAVE AS dialogue box type: week2_2009_

. *Obtain histogram again but now with overlay of normal using option NORMAL . histogram boiling, normal (bin=5, start=12.267, width=3.3888) . *save graph as week2_2009_2.png . * Fit of simple line using command REGRESS with y variable first then x variable . regress boiling temp

Source | SS df MS Number of obs = 31 -------------+------------------------------ F( 1, 29) = 336. Model | 450.558755 1 450.558755 Prob > F = 0. Residual | 38.8187237 29 1.33857668 R-squared = 0. -------------+------------------------------ Adj R-squared = 0. Total | 489.377479 30 16.3125826 Root MSE = 1.

boiling | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- temp | .4437942 .0241895 18.35 0.000 .3943211. _cons | -65.343 4.643815 -14.07 0.000 -74.84067 -55.


. * Graph of the 95% Confidence Interval of the Predicted Mean . twoway lfitci boiling temp . *save graph as week2_2009_4.png . * Another Graph of the 95% Confidence Interval of the Predicted Mean . * Option CIPLOT(RLINE) produces confidence interval as lines instead of shading . twoway lfitci boiling temp, ciplot(rline) . *save graph as week2_2009_5.png

. *Obtain graph of 95% confidence interval of individual predictions . twoway lfitci boiling temp, stdf ||scatter boiling temp . *save graph as week2_2009_6.png . *Close the log . *File --> LOG --> CLOSE . log close log: /Users/carolbigelow/Desktop/week2_2009.log log type: text closed on: 8 Feb 2009, 18:38: