Thursday, November 3, 2016

Stata Hint on Recoding a Contingency Table

Stata Hint on Recoding a Contingency Table

Question:   Consider the five-by-five two-way contingency table for the relationship between mental health and general health for people over 75 years of age.

Two-Way Contingency Table for Perceived Mental Health and General Health  -- Five Categories
Perceived General Health
Perceived Mental Health
Excellent
Very Good
Good
Fair
Poor
Total
Excellent
151
109
73
31
8
372
Very Good
37
199
116
48
8
408
Good
27
89
261
110
25
512
Fair
7
7
42
95
29
180
Poor
1
1
13
24
28
67
223
405
505
308
98
1539

Over age 75 based on data in the 2014 MEPS survey.


I have decided that I want to deal with a three-group contingency table where the health and mental health status groups are 1) excellent, 2) Middle (composed of very good, good and fair) and 3) poor.  How can I make this recode in Stata.

Discussion of recoding in STATA:

The basic five-group general health and mental health variables used in this analysis are RTHLTH31 and MNHLTH31.  The health perception variables in MEPS actually have 9 outcomes.   The four outcomes less than zero involve data that was not available.   The five main outcomes are – 1 excellent, 2 very good, 3 good, 4 fair, and 5 poor. 

I remove observations less than zero by adding the following statement to the tabulate command

if (MNHLTH31>0) & (RTHLTH31>0)

I create an age dummy variable that allows me to run the tabulate procedure for different age groups.

Age in MEPS can be created by

generate Age=2014-dobyy

After creating age create age dummy variables.  The following dummy variable is 1 for age greater than 75 and 0 otherwise

generate old = (age>75)

The following recode commands are used to transform the five-category mental and general health questions into three categories where the middle group is composed  of people with very good (2), good (3) and fair (4) health or mental health.

generate byte mh3=recode(MNHLTH31,1,4,5)

generate byte gh3=recode(RTHLTH31,1,4,5)

I run the tabulate command by the age dummy.


. by old, sort : tabulate mh3 gh3 if (MNHLTH31>0) & (RTHLTH31>0)


The three-group two-way contingency table is below.


Two Way Contingency Table for Mental and General Health
 -- Three Group Example
General Health
Mental Health
Excellent
Fair to Very Good
Poor
Excellent
151
213
8
372
Fair to Very Good
71
967
62
1100
Poor
1
38
28
67
223
1218
98
1539
Over Age 75 based on data in the 2014 MEPS survey.


Authors Note:  I am doing a lot of work with the MEPS database on the affordable care act.   Much of my recent work including this research proposal is published in my blog.




No comments:

Post a Comment