[rkward-devel] rkward import module for Stata
Michael Ash
mash at econs.umass.edu
Sat Sep 26 15:25:12 UTC 2009
> 2) I believe Stata also has support for variable labels? If so, then it would
> be nice to convert those labels to the RKWard format as is done in the
> import_spss plugin. (Be sure to include one or two variable labels in the
> sample file).
>
> Labeled values of factors are set automatically by read.dta()
>
> Variable labels are included by read.dta() as an attribute of the
> data.frame and can be accessed with:
>
> attr (data, "var.labels")
I am attaching a new version of import_stata.php that correctly
handles variable labels (the structure of the attribute differed
slightly between SPSS and Stata: first, the attribute is var.labels
rather than variable.labels; second, the var.labels attribute did not
have variable names as column names; so the match has to be done by
column number). Here is the relevant stretch of code for importing
Stata variable labels.
# set variable labels for use in RKWard
labels <- attr (data, "var.labels")
if (!is.null (labels)) {
for (i in 1:length (labels)) {
col <- make.names (attr (data, "names")[i] )
if (!is.null (col)) {
rk.set.label (data[[col]], labels[i])
}
}
}
Try this on
http://wps.aw.com/wps/media/objects/3254/3332253/datasets2e/datasets/Smoking.dta
and you should see the labels for the variables.
Best,
Michael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: import_stata.php
Type: application/x-httpd-php
Size: 1663 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/rkward-devel/attachments/20090926/00ef716b/attachment.bin>
More information about the Rkward-devel
mailing list