Skip to content

Importint stata file and using value labels

13 messages · Rui Barradas, Jeff Newmiller, Juan Ceccarelli Arias +3 more

#
Hi
Im a bit lost.
Ive imported a stata13 file. When i try to make a simple
table(region[sex=1],type[sex=1])
i get something as
           type1 type2
region1 0 0
region2 0 0
region3 0 0

I don't know how to operate with the value labels.
Sex is defined as 1 as "Man" and 2 as "Female".
And region1 is 1, region2 is 2 and so on.
So, how can i make reference to the value and not the value labels when i
write down some condition or statement ?
I know is simple, but using the help for readstata13 didn't clarify it to
me.
Thanks for your help and time.
#
Hello,

Try instead

table(region[sex==1],type[sex==1])

To test for equality use == not =.

Hope this helps,

Rui Barradas
?

Citando Juan Ceccarelli Arias <jfca283 at gmail.com>:
?
#
Nop. I didn't work. But using the following it does work.
table(region[sex=="Men"],type[sex=="Men"])
When i use the dta file with stata i declare the condition with sex==1 and
not sex=="Man".
On Thu, Aug 25, 2016 at 12:39 PM, <ruipbarradas at sapo.pt> wrote:

            

  
  
#
Maybe sex is a factor and Man its label. Factors are coded internally  
as integers, to see it use

str(sex)

Rui Barradas
?

Citando Juan Ceccarelli Arias <jfca283 at gmail.com>:
?
#
Factor w/ 2 levels "Hombre","Mujer": 1 2 2 1 2 2 1 1 1 1 ...
On Thu, Aug 25, 2016 at 1:42 PM, <ruipbarradas at sapo.pt> wrote:

            

  
  
#
You need to (re-)read the "Introduction to R" document that comes with R. R Is not Stata, and you should not expect R to look syntactically like Stata.

Note that if you, against normal R convention, wish to manipulate the integers that a factor is implemented with,  you can create such a variable using as.integer( sex ), but beware that bad data or changes made to the factor definition before your analysis step will render your assumptions about specific integer values invalid. For example the order of levels for sex might go c("M","F") or c("F","M") so 1 could mean different things based on decisions made elsewhere.
#
So you should do

table(region[sex=="Hombre"],type[sex=="Hombre"]

Rui Barradas
?

Citando Juan Ceccarelli Arias <jfca283 at gmail.com>:
?
#
Mmm...The other option working with  R for importing the dta file but
obtaining the values and deleting or ignoring the value labels.
I think some time ago i did that, but now i can't remember it.
On Thu, Aug 25, 2016 at 4:11 PM, <ruipbarradas at sapo.pt> wrote:

            

  
  
#
Hi

You can use

as.numeric(sex)

to get numeric values for factor variable. This is sometimes handy for plotting.

However if you throw away labels how do you know what naumber belongs to which factor level?

Cheers
Petr
________________________________
Tento e-mail a jak?koliv k n?mu p?ipojen? dokumenty jsou d?v?rn? a jsou ur?eny pouze jeho adres?t?m.
Jestli?e jste obdr?el(a) tento e-mail omylem, informujte laskav? neprodlen? jeho odes?latele. Obsah tohoto emailu i s p??lohami a jeho kopie vyma?te ze sv?ho syst?mu.
Nejste-li zam??len?m adres?tem tohoto emailu, nejste opr?vn?ni tento email jakkoliv u??vat, roz?i?ovat, kop?rovat ?i zve?ej?ovat.
Odes?latel e-mailu neodpov?d? za eventu?ln? ?kodu zp?sobenou modifikacemi ?i zpo?d?n?m p?enosu e-mailu.

V p??pad?, ?e je tento e-mail sou??st? obchodn?ho jedn?n?:
- vyhrazuje si odes?latel pr?vo ukon?it kdykoliv jedn?n? o uzav?en? smlouvy, a to z jak?hokoliv d?vodu i bez uveden? d?vodu.
- a obsahuje-li nab?dku, je adres?t opr?vn?n nab?dku bezodkladn? p?ijmout; Odes?latel tohoto e-mailu (nab?dky) vylu?uje p?ijet? nab?dky ze strany p??jemce s dodatkem ?i odchylkou.
- trv? odes?latel na tom, ?e p??slu?n? smlouva je uzav?ena teprve v?slovn?m dosa?en?m shody na v?ech jej?ch n?le?itostech.
- odes?latel tohoto emailu informuje, ?e nen? opr?vn?n uzav?rat za spole?nost ??dn? smlouvy s v?jimkou p??pad?, kdy k tomu byl p?semn? zmocn?n nebo p?semn? pov??en a takov? pov??en? nebo pln? moc byly adres?tovi tohoto emailu p??padn? osob?, kterou adres?t zastupuje, p?edlo?eny nebo jejich existence je adres?tovi ?i osob? j?m zastoupen? zn?m?.

This e-mail and any documents attached to it may be confidential and are intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. Delete the contents of this e-mail with all attachments and its copies from your system.
If you are not the intended recipient of this e-mail, you are not authorized to use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately accept such offer; The sender of this e-mail (offer) excludes any acceptance of the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into any contracts on behalf of the company except for cases in which he/she is expressly authorized to do so in writing, and such authorization or power of attorney is submitted to the recipient or the person represented by the recipient, or the existence of such authorization is known to the recipient of the person represented by the recipient.
#
Yep. Im a bit stalled.
I can't find the option to import only the values and drop the value labels
from the dta file.
Im quite sure R can do that. Then i'd only used the values and i'd rely on
my memory.
It isn't a bad alternative.
On Fri, Aug 26, 2016 at 4:11 AM, PIKAL Petr <petr.pikal at precheza.cz> wrote:

            

  
  
1 day later
#
On 8/26/2016 11:05 AM, Juan Ceccarelli Arias wrote:
Hint: use str() to see the class of what you've read.
Then try as.data.frame() on the resulting object read from the .dta file.
#
There has been some good advice not to lose the labels, but perhaps this 
gets you where you seem determined to go?

?read.dta

read.dta(file, convert.dates = TRUE, convert.factors = TRUE,
          missing.type = FALSE,
          convert.underscore = FALSE, warn.missing.labels = TRUE)

or

library(readstata13)

?read.dta13

read.dta13(file, convert.factors = TRUE, generate.factors = FALSE,
   encoding = NULL, fromEncoding = NULL, convert.underscore = FALSE,
   missing.type = FALSE, convert.dates = TRUE, replace.strl = FALSE,
   add.rownames = FALSE, nonint.factors = FALSE)

Perhaps the convert. factors setting at FALSE?
On 08/27/2016 10:55 AM, Michael Friendly wrote:
4 days later
#
I solved this problem using the
nonint.factors=F,generate.factors=F)
when i imported the dta files.
Thanks to all. My issue can be declared as solved.


On Sat, Aug 27, 2016 at 12:55 PM, Michael Friendly <friendly at yorku.ca>
wrote: