## Setting paths to SHP data files. Adapt to your local folders!
## It should be something like
## wavedir <- "C:/SwissHPanel/shp23/SHP-Data-W1-W23-SPSS/"
## datadir <- "C:/SwissHPanel/shp23/SHP-Data-WA-SPSS/"
## Consider first the example of 3 waves and a MP file
## shipping with the package
wavedir <- paste0(system.file(package="seqSHP"),"/extdata/")
datadir <- wavedir
####### Working status
first.w <- 1
last.w <- 3
waves <- first.w:last.w
maxMissing <- 2
## Sequence of categorical variables
## WSTAT$$ is working status (WS)
shp <- seqFromWaves(wavedir, datadir,
pvarseq="WSTAT$$",
waves=waves, maxMissing=maxMissing)
## Retrieve WS labels
attr(shp$WSTAT00,"labels")
## Creating WS sequence object
library(TraMineR)
ws.shortlab <- c("AO","UN","NL")
ws.longlab <- c("Active Occupied","Unemployed","Not in Labor Force")
ws.alph <- c(1,2,3)
xtlab <- (1998+first.w):(1998+last.w)
wsvar <- getColumnIndex(shp, "WSTAT$$")
ws.seq <- seqdef(shp[, wsvar], right=NA,
alphabet=ws.alph, states=ws.shortlab, labels=ws.longlab,
cnames=xtlab)
## plotting first 100 sequences
seqIplot(ws.seq[1:100,], sort="from.start")
if (FALSE) {
####################################################
## To run the full examples below, you must first install SHP data
## in an accessible folder
##
## Adapt to your local folders!
wavedir <- "C:/SwissHPanel/shp23/SHP-Data-W1-W23-SPSS/"
datadir <- "C:/SwissHPanel/shp23/SHP-Data-WA-SPSS/"
####### Working status
first.w <- 2
last.w <- 23
waves <- first.w:last.w
maxMissing <- 10
## Sequence of categorical variables
## WSTAT$$ is working status (WS) and
## P$$C44 satisfaction with life
shp <- seqFromWaves(wavedir, datadir,
pvarseq=c("WSTAT$$","P$$C44"),
waves=waves, maxMissing=maxMissing)
## Retrieve WS labels
attr(shp$WSTAT00,"labels")
## Creating WS sequence object
library(TraMineR)
ws.shortlab <- c("AO","UN","NL")
ws.longlab <- c("Active Occupied","Unemployed","Not in Labor Force")
ws.alph <- c(1,2,3)
xtlab <- (1998+first.w):(1998+last.w)
wsvar <- getColumnIndex(shp, "WSTAT$$")
ws.seq <- seqdef(shp[, wsvar], right=NA,
alphabet=ws.alph, states=ws.shortlab, labels=ws.longlab,
cnames=xtlab, xtstep=2, tick.last=TRUE)
seqIplot(ws.seq, sort="from.start")
######### Activity calendar from sep99 to dec2021
month.short.names <- tolower(sapply(month.name, substr, 1, 3))
xtlab.ca <- c("sep99","oct99","nov99","dec99")
for (t in 00:21) {
xtlab.ca <- c(xtlab.ca,paste0(month.short.names, formatC(t,width=2,flag=0)))
}
names(xtlab.ca) <- xtlab.ca
ca.var <- toupper(xtlab.ca) ## SPSS variable names are uppercase
CAseqdata <- seqFromWaves(wavedir, datadir, CAvar=ca.var, maxMissingCA=36)
attr(CAseqdata$SEP99, "labels")
## First 3 columns are IDPERS, SEX, and BIRTHY. Sequences from the other columns
seqCA <- seqdef(CAseqdata[,-(1:3)], cnames=xtlab.ca, right=NA, xtstep=6, tick.last=TRUE)
seqdplot(seqCA, border=NA, with.missing=TRUE)
}
Run the code above in your browser using DataLab