Statistical Analysis and Plotting Example for Evaluating Relationship between Variables - , Lab Reports of Epidemiology

An example of statistical analysis using the stata software to evaluate the relationship between pain at time of entry (paine) and age group (agegrp) by computing mean pain level for each age group, separately for males and females, using the ankle_full.dta dataset. It also demonstrates plotting the mean pain level against age group with two curves, one for males and one for females.

Typology: Lab Reports

Pre 2010

Uploaded on 03/10/2009

koofers-user-fc3
koofers-user-fc3 🇺🇸

9 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
PLOTTING EXAMPLE
Biostat/Epi 536 Discussion Session – November 4, 2008
Using the ankle_full.dta dataset from the course website, we wish to evaluate the
relationship between pain at time of entry (PAINE) and age group (AGEGRP) by computing mean
pain level for each age group. We wish to do this separately for males and females (SEX).
. table PAINE
----------------------
Pain |
scale at |
time on |
entry | Freq.
----------+-----------
0 | 32
1 | 47
2 | 68
3 | 72
4 | 92
5 | 106
6 | 78
7 | 67
8 | 48
9 | 32
10 | 18
----------------------
gen agegrp=.
replace agegrp=1 if AGE < 19
replace agegrp=2 if AGE >= 19 & AGE < 24
replace agegrp=3 if AGE >= 24 & AGE < 37
replace agegrp=4 if AGE >= 37 & AGE < 55
replace agegrp=5 if AGE >= 55 & AGE < 86
replace agegrp=6 if AGE >= 86 & AGE <= 90
label define age 1 "13-18" 2 "19-23" 3 "24-36" 4 "37-54" 5 "55-85" 6 "86-90"
label values agegrp age
. table agegrp
----------------------
agegrp | Freq.
----------+-----------
13-18 | 148
19-23 | 176
24-36 | 174
37-54 | 99
55-85 | 65
86-90 | 3
----------------------
. table SEX
----------------------
SEX | Freq.
----------+-----------
Male | 379
Female | 286
----------------------
pf3
pf4

Partial preview of the text

Download Statistical Analysis and Plotting Example for Evaluating Relationship between Variables - and more Lab Reports Epidemiology in PDF only on Docsity!

PLOTTING EXAMPLE

Biostat/Epi 536 Discussion Session – November 4, 2008

Using the ankle_full.dta dataset from the course website, we wish to evaluate the

relationship between pain at time of entry (PAINE) and age group (AGEGRP) by computing mean

pain level for each age group. We wish to do this separately for males and females (SEX).

. table PAINE

Pain | scale at | time on | entry | Freq. ----------+----------- 0 | 32 1 | 47 2 | 68 3 | 72 4 | 92 5 | 106 6 | 78 7 | 67 8 | 48 9 | 32 10 | 18


gen agegrp=. replace agegrp=1 if AGE < 19 replace agegrp=2 if AGE >= 19 & AGE < 24 replace agegrp=3 if AGE >= 24 & AGE < 37 replace agegrp=4 if AGE >= 37 & AGE < 55 replace agegrp=5 if AGE >= 55 & AGE < 86 replace agegrp=6 if AGE >= 86 & AGE <= 90

label define age 1 "13-18" 2 "19-23" 3 "24-36" 4 "37-54" 5 "55-85" 6 "86-90" label values agegrp age

. table agegrp


agegrp | Freq. ----------+----------- 13-18 | 148 19-23 | 176 24-36 | 174 37-54 | 99 55-85 | 65 86-90 | 3


. table SEX

SEX | Freq. ----------+----------- Male | 379 Female | 286


We begin by calculating the mean pain level for each age group, first overall

. tabstat PAINE, stat(mean) by(agegrp) notot

Summary for variables: PAINE by categories of: agegrp

agegrp | mean -------+---------- 13-18 | 4. 19-23 | 4. 24-36 | 4. 37-54 | 5. 55-85 | 3. 86-90 | 5.


then separately for males (SEX==1) and for females (SEX==2).

. tabstat PAINE if SEX==1, stat(mean) by(agegrp) notot

Summary for variables: PAINE by categories of: agegrp

agegrp | mean -------+---------- 13-18 | 4. 19-23 | 4. 24-36 | 4. 37-54 | 5. 55-85 | 3.


. tabstat PAINE if SEX==2, stat(mean) by(agegrp) notot

Summary for variables: PAINE by categories of: agegrp

agegrp | mean -------+---------- 13-18 | 5. 19-23 | 5. 24-36 | 4. 37-54 | 5. 55-85 | 3. 86-90 | 5.


Next, we create the plotting variable meanpaine containing, for each subject, the mean pain

level for that subject’s age group.

. gen meanpaine = (agegrp==1)4.38 + (agegrp==2)4.59 + (agegrp==3)4.65 + (agegrp==4)5.11 + (agegrp==5)*3.17 if SEX==

This command stores mean pain levels for males as meanpaine. Mean pain levels for females

are set equal to missing. Thus, we follow with

. replace meanpaine = (agegrp==1)5.37 + (agegrp==2)5.36 + (agegrp==3)4.17 + (agegrp==4)5.15 + (agegrp==5)3.9 + (agegrp==6)5.67 if SEX==

We use following commands to save the means from the first tabstat (SEX==1) into a matrix

called matrix1 and the means from the second tabstat (SEX==2) into a matrix called

matrix2. Note that as (agegrp==6 ) has no observations for males (SEX==1), we have

replaced r(Stat6) with a period. to indicate a missing value for the mean.

. tabstat PAINE if SEX==2, stat(mean) by(agegrp) notot save . matrix matrix2 = (r(Stat1)\r(Stat2)\r(Stat3)\r(Stat4)\r(Stat5)\ r(Stat6) ) . svmat matrix . tabstat PAINE if SEX==1, stat(mean) by(agegrp) notot save . matrix matrix1 = (r(Stat1)\r(Stat2)\r(Stat3)\r(Stat4)\r(Stat5)*.* ) . svmat matrix

STATA has placed the mean values for males into the first five observations in the dataset (in a

column labeled matrix11) and the mean values for females into the first six observations in the

dataset (in a column labeled matrix21).

[Aside] in the project, you will need to make a graph where the first 2 categories have no

observations. Insert periods for the first 2 observations, and begin with r(Stat1) for the 3

rd

category, so the means are plotted for the appropriate age categories on your graph:

matrix matrix3=(..\r(Stat1)\r(Stat2)\r(Stat3)\r(Stat4)\r(Stat5)
r(Stat6)\r(Stat7)\r(Stat8))

Next, it is necessary to create a plotting variable to represent age group.

. gen plotage = _n if _n <= 6

We can label the variable plotage using the same label that we used to label the variable

agegrp

. label values plotage age

and plot as follows:

. twoway (connected matrix11 plotage) (connected matrix21 plotage), ytitle(Mean pain level) xtitle(Age group) xlabel(1(1)6, labels valuelabel) legend(order(1 "Males" 2 "Females"))

3

4

5

6

Mean pain level

1 2 3 4 5 6 Age group Males Females