[R] Converting ddf/dct/sas data definition file to R

Stephan Lindner
Thu, 22 Jan 2009 18:48:55 -0000

Dear all,

I was wondering whether anyone knows about a program which converts
(part of) a data definition file (such as a .dct file for stata, or
.sas file for sas) into an R-script.

Here is an example with a .sas file:

<-- snipp

VALUE HTYPE   	(default=32)
	0         =  "Not in household"
	1         =  "Married couple family household"
	2         =  "Male householder family"
	3         =  "Female householder family"
	4         =  "Male householder nonfamily"
	5         =  "Female householder nonfamily"
	6         =  "Group quarters"
;

snapp -->


This entry defines the variable HTYPE as a factor and assigns levels
and labels. Ideally, it would be transformed into the following entry
in R:


data.frame$HTYPE <- factor(data.frame$HTYPE,
	levels=c(0,1,2,3,4,5,6),
	labels=c("Not in household",
		 "Married couple family household",
		 "Male householder family",
		 "Female householder family",
		 "Male householder nonfamily",
		 "Female householder nonfamily",
		 "Group quarters"
                )
	)


Of course, this can be done by hand and isn't too bad with a good text
editor. The reason why I am looking for a program is because I have a
bunch of datasets (about 100) and there are about 200 variables defined
per dataset. My goal is to provide R-scripts for these datasets such
that the data files can be read in with R, making them accessible for
R users.



Thanks!


	Stephan






--
-----------------------
Stephan Lindner
University of Michigan