Skip to content

stata.get labels glm()

4 messages · Quark at gmx.at, Ben Bolker, Tobias Caris

#
Dear R community,

I would like to import data saved with Stata and then run a Probit model using R.

My data comes from the World Values Surveys and in the Probit model I want to control for countries.

So far I figured out that I should put "convert.factors = FALSE" when using stata.get() in order to import numeric values instead of label mappings, which is what I want for most of the variables. In a second step I would like to convert ONLY the country variable to a factor, such that glm() automatically controls for countries. With the latter point I am stuck, I managed to extract the country labels but don't know how to match this information now with my country variable 'v2'.
japan       mexico south africa      hungary    australia       tambov    argentina      finland  south korea 
13           14           15           16           17           20           22           23           24 



I know that I could put the option factor() in the Probit model but in my output then '13' instead of 'Japan' appears, which is not so nice, i.e.
Thanks a lot for your help.

Best regards,

Tobias
#
<Quark <at> gmx.at> writes:
[snip]


 [snip]

  Why don't you set convert.factors to TRUE and convert the
particular values you are interested in into numeric labels after
you import them into R?

wvs1981 <- transform(wvs1981,
    v214=as.numeric(v214),
    v216=as.numeric(v216))
glm(v220bin ~ v214 + v216 + v2, ...)

  ?
#
Thanks for the idea, Ben. It works, but unfortunately the numbers assigned by as.numeric() do not correspond to the original coding.

Any other suggestions are very much appreciated.

Best regards, Tobias



-------- Original-Nachricht --------

  
    
#
ok, solved it.

In case anyone else is interested:

1st step: import data with convert.factors = FALSE

2nd step: replace only for variable v2 numeric values to labels:

wvs1981$v2 <- factor(wvs1981$v2, labels = labels(attributes(wvs1981)$stata.info$label.table$v2))




-------- Original-Nachricht --------
-- 
GMX DSL Doppel-Flat ab 19,99 Euro/mtl.! Jetzt mit 
gratis Handy-Flat! http://portal.gmx.net/de/go/dsl