# NOT RUN {
## Asthma Example from Essential Medical Statistics
## page 160
asthma <- expandtbl(c(81, 995, 57, 867),
exp_name = "sex",
exp_lvl = c("woman", "man"),
case_name = "asthma",
case_lvl = c("yes", "no"))
# }
# NOT RUN {
## label variable and dataset
asthma <- label(asthma, "Hypothetical Data of Asthma Prevalence")
asthma <- label(asthma, sex = "Man or Woman",
asthma = "Asthma or No Asthma")
## Checking codebook
codebook(asthma)
## simple tabulation
tab(asthma)
## cross-tabulation
tab(asthma, sex, by = asthma)
# }
# NOT RUN {
## Example for expanding frequency weighted data
## Example from UCLA website
## you can download the dataset here:
## https://stats.idre.ucla.edu/stat/stata/examples/icda/afterlife.dta
x <- data.frame(gender = c(1, 1, 0, 0),
aftlife = c(1, 0, 1, 0),
freq = c(435, 147, 375, 134))
y <- expandfreq(x, freq)
## check the numbers by tabulation
## tab(y, gender, by = aftlife)
# }
Run the code above in your browser using DataLab