[rkward-devel] rkward import module for Stata

Michael Ash mash at econs.umass.edu
Sat Sep 26 12:50:06 UTC 2009


On Tuesday 22 September 2009, Michael Ash wrote:
> I have used the import_spss template to write an import_stata module.
> I changed the various options and flags from the read.spss() command
> to the read.dta() options. So far it is working for me, although it
> is possible that the code could be cleaned up. I'd be grateful for
> feedback or suggestions and will make changes that are within my
> limited programming capability. If the code is ok, maybe it can be
> included in the next release.

many thanks for your contribution. This will be very useful to have. Looks
good overall, but a few comments:

1) Could you construct a small sample stata file that we can use for testing?
Ideally this would contain a number of variables of different types, with &
without value labels, special missing values, etc. This is both to help us
testing right now, and to create an automated test for your plugin, later
(http://sourceforge.net/apps/mediawiki/rkward/index.php?title=Automated_Plugin_Testing).


I am attaching two not-so-small files for testing (one has value
labels, one has variable labels).  I will construct a single smaller
file soon when I have access to Stata.

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")

Here is the section of code that I am writing but it's not working
yet.  I get "Error in .subset2(x, i, exact = exact) :
  attempt to select less than one element"

# 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 (names (labels[i]))
                if (!is.null (col)) {
                        rk.set.label (data[[col]], labels[i])
                }
        }
}






3) The <logic>-section still has references to the "use_label" checkbox from
the import_spss plugin. Those should be cleaned up.

I have pulled these out and am attaching the new import_stata.xml file

I have also cleaned up the help file import_stata.rkh  and am
attaching that as well.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: import_stata.xml
Type: text/xml
Size: 1455 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/rkward-devel/attachments/20090926/c64c4f93/attachment.xml>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: import_stata.rkh
Type: application/octet-stream
Size: 1712 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/rkward-devel/attachments/20090926/c64c4f93/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Smoking.dta
Type: application/octet-stream
Size: 101736 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/rkward-devel/attachments/20090926/c64c4f93/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: chap5-cps.dta
Type: application/octet-stream
Size: 108386 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/rkward-devel/attachments/20090926/c64c4f93/attachment-0002.obj>


More information about the Rkward-devel mailing list