Examples

• Simple cross-wave comparisons:
• crosstabulations of categorical variables
• correlations of continuous variables
• For instance, change in vote intention between waves:
get file 's:\bhps\spss\dindresp.sav'/keep=pid,dvote,asex.
sort cases by pid.
save out = 'c:\temp\tempd.sav'.
get file 's:\bhps\spss\eindresp.sav'/keep=pid,evote,esex.
sort cases by pid.

match files file=*/file='c:\temp\tempd.sav'/by=pid.
missing values all (-9 thru -1).
recode dvote evote (4 thru 10=7).
cro dvote by evote by dsex/cell = count row.

Stata:
use pid dvote dsex using s:\bhps\stata\dindresp
sort pid
save c:\temp\tempd,replace

use pid evote esex using s:\bhps\stata\eindresp
sort pid

merge pid using c:\temp\tempd

recode dvote -9/-1=. 4/10=7
recode evote -9/-1=. 4/10=7

bysort dsex: tab dvote evote, row


• Inspection of the table is interesting but we can go farther:
• Calculate the proportion on and off the diagonal
• Fit loglinear models

• We can fit a regression model relating income at one wave to characteristics at a prior wave (including income):

missing values all (-9 thru -1).
reg dep=bfimn /method=enter afimn ajbstat asex amastat.

• or

compute delta = bfimn - afimn.
reg dep=delta /method=enter ajbstat asex amastat.


Stata:

recode bfimn -9/-1=1
recode ...
xi: reg bfimn afimn i.ajbstat i.asex i.amastat

• or
get delta = bfimn - afimn
xi: reg delta i.ajbstat i.asex i.amastat


• For binary outcomes logistic regression on the same logic:
compute bempl = any(bjbstat,1,2).
logistic bempl /cat ajbstat asex aregion
/method = enter ajbstat asex aregion afimn.

Stata:
gen bempl = inlist(bjbstat,1,2)
xi: logit bempl i.ajbstat i.asex i.aregion afimn


• Those analyses are all based on specific pairs of waves.
• We may also want to look at all pairs of waves (i.e., all transitions) simultaneously
• For this we need the long format:
  ID   Wave Empstat          ID   Wave Empstat P-empstat
1      1      1            1      1      1       .
1      2      1  ------>   1      2      1       1
1      3      4            1      3      4       1
1      4      1            1      4      1       4


• An alternative way to generate the long format is to append files rather than match-merge them:
add files file = 's:\bhps\spss\aindresp.sav'
/rename(ajbstat=emp) /in=w1
/file = 's:\bhps\spss\bindresp.sav'
/rename(bjbstat=emp) /in=w2
/file = 's:\bhps\spss\cindresp.sav'
/rename(cjbstat=emp) /in=w3
/file = 's:\bhps\spss\dindresp.sav'
/rename(djbstat=emp) /in=w4
/keep=pid,emp.

if w1 wave=1.
if w2 wave=2.        * Continued.../
if w3 wave=3.
if w4 wave=4.

sort cases by pid,wave.

if pid=lag(pid) pemp = lag(emp).
exec.
sel if not missing(pemp).
missing values all (-9 thru -1).
cro pemp by emp/cell = row count.

Stata:
use ajbstat asex using s:\bhps\stata\aindresp
gen wave=1
renpfix a
save c:\temp\tempa,replace
use bjbstat bsex using s:\bhps\stata\bindresp
gen wave=2
renpfix b
save c:\temp\tempb,replace
use cjbstat csex using s:\bhps\stata\cindresp
gen wave=3
renpfix c
save c:\temp\tempc,replace
use djbstat dsex using s:\bhps\stata\dindresp
gen wave=4
renpfix d
save c:\temp\tempd,replace

use c:\temp\tempa
append using c:\temp\tempb
append using c:\temp\tempc
append using c:\temp\tempd

sort pid wave

by pid: gen pjbstat=jbstat[_n-1]


• This table pools all wave-on-wave transitions, but we can retrieve the wave specific ones thus:
cro pemp by emp by wave/cell = row count.
. . .
temp.
sel if wave=4.
cro pemp by emp/cell = row count.

Stata:
tab pjbstat by jbstat if wave==4


 © Brendan Halpin (e-mail) 23-Apr-2012 Department of Sociology, University of Limerick Taught programme: MA in Sociology (Applied Social Research), Short course, May 14/15 2012: Categorical Data Analysis for Social Scientists