codebook {memisc}R Documentation

Generate a Codebook of a Data Set

Description

Function codebook collects documentation about an item, or the items in a data set or external data file. It returns an object that, when shown, print this documentation in a nicely formatted way.

Usage

codebook(x)
## S4 method for signature 'data.set'
codebook(x)
## S4 method for signature 'importer'
codebook(x)

Arguments

x

an item, data.set or importer object for codebook()

Value

An object of class "codebook", for which a show method exists that produces a nicely formatted output.

Examples

Data <- data.set(
          vote = sample(c(1,2,3,8,9,97,99),size=300,replace=TRUE),
          region = sample(c(rep(1,3),rep(2,2),3,99),size=300,replace=TRUE),
          income = exp(rnorm(300,sd=.7))*2000
          )

Data <- within(Data,{
  description(vote) <- "Vote intention"
  description(region) <- "Region of residence"
  description(income) <- "Household income"
  wording(vote) <- "If a general election would take place next tuesday,
                    the candidate of which party would you vote for?"
  wording(income) <- "All things taken into account, how much do all
                    household members earn in sum?"
  foreach(x=c(vote,region),{
    measurement(x) <- "nominal"
    })
  measurement(income) <- "ratio"
  labels(vote) <- c(
                    Conservatives         =  1,
                    Labour                =  2,
                    "Liberal Democrats"   =  3,
                    "Don't know"          =  8,
                    "Answer refused"      =  9,
                    "Not applicable"      = 97,
                    "Not asked in survey" = 99)
  labels(region) <- c(
                    England               =  1,
                    Scotland              =  2,
                    Wales                 =  3,
                    "Not applicable"      = 97,
                    "Not asked in survey" = 99)
  foreach(x=c(vote,region,income),{
    annotation(x)["Remark"] <- "This is not a real survey item, of course ..."
    })
  missing.values(vote) <- c(8,9,97,99)
  missing.values(region) <- c(97,99)
})

description(Data)
## 
##  vote   'Vote intention'     
##  region 'Region of residence'
##  income 'Household income'
codebook(Data)
## ===========================================================================
## 
##    vote 'Vote intention'
## 
##    "If a general election would take place next tuesday, the candidate of
##    which party would you vote for?"
## 
## ---------------------------------------------------------------------------
## 
##    Storage mode: double
##    Measurement: nominal
##    Missing values: 8, 9, 97, 99
## 
##             Values and labels    N    Percent 
##                                               
##     1   'Conservatives'         41   30.8 13.7
##     2   'Labour'                39   29.3 13.0
##     3   'Liberal Democrats'     53   39.8 17.7
##     8 M 'Don't know'            43        14.3
##     9 M 'Answer refused'        45        15.0
##    97 M 'Not applicable'        38        12.7
##    99 M 'Not asked in survey'   41        13.7
## 
##    Remark:
## 
##        This is not a real survey item, of course ...
## 
## ===========================================================================
## 
##    region 'Region of residence'
## 
## ---------------------------------------------------------------------------
## 
##    Storage mode: double
##    Measurement: nominal
##    Missing values: 97, 99
## 
##             Values and labels    N    Percent 
##                                               
##     1   'England'              139   53.3 46.3
##     2   'Scotland'              79   30.3 26.3
##     3   'Wales'                 43   16.5 14.3
##    97 M 'Not applicable'         0         0.0
##    99 M 'Not asked in survey'   39        13.0
## 
##    Remark:
## 
##        This is not a real survey item, of course ...
## 
## ===========================================================================
## 
##    income 'Household income'
## 
##    "All things taken into account, how much do all household members earn
##    in sum?"
## 
## ---------------------------------------------------------------------------
## 
##    Storage mode: double
##    Measurement: ratio
## 
##             Min:    112.638
##             Max:  21944.655
##            Mean:   2596.105
##        Std.Dev.:   2195.542
##        Skewness:      3.775
##        Kurtosis:     23.513
## 
##    Remark:
## 
##        This is not a real survey item, of course ...
## Not run: 
##D Write(descrition(Data),
##D            file="Data-desc.txt")
##D Write(codebook(Data),
##D            file="Data-cdbk.txt")
##D   
## End(Not run)

[Package memisc version 0.97 Index]