Juan Ceccarelli Arias
2016-Aug-26 15:05 UTC
[R] Importint stata file and using value labels
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:> 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 > > > -----Original Message----- > > From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Juan > > Ceccarelli Arias > > Sent: Thursday, August 25, 2016 9:15 PM > > To: ruipbarradas at sapo.pt > > Cc: r-help at r-project.org > > Subject: Re: [R] Importint stata file and using value labels > > > > 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: > > > > > So you should do > > > > > > table(region[sex=="Hombre"],type[sex=="Hombre"] > > > > > > Rui Barradas > > > > > > > > > Citando Juan Ceccarelli Arias <jfca283 at gmail.com>: > > > > > > str(sex) > > >>> > > >> 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: > > >> > > >>> _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>:_ > > >>> > > >>> _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: _ > > >>>> > > >>>>> __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>:__ > > >>>>> > > >>>>> _ _ > > >>>>>> __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. > > >>>>>> _ > > >>>>>> > > >>>>>> __ [[alternative HTML version deleted]] > > >>>>>> > > >>>>>> _______________________________________________ > > >>>>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > >>>>>> https://stat.ethz.ch/mailman/listinfo/r-help > > >>>>>> PLEASE do read the posting guide http://www.R-project.org/posti > > >>>>>> ng-guide.htmland provide commented, minimal, self-contained, > > >>>>>> reproducible code. _ _ _ _ _ > > >>>>>> > > >>>>> > > >>>>> __ __ > > >>>>> > > >>>> > > >>>> _ _ > > >>>> _ _ > > >>>> > > >>> > > >>> _ _ > > >>> > > >> > > > > > > > > > > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting- > > guide.html > > and provide commented, minimal, self-contained, reproducible code. > > ________________________________ > 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. >[[alternative HTML version deleted]]
On 8/26/2016 11:05 AM, Juan Ceccarelli Arias wrote:> 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. >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. -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. & Chair, Quantitative Methods York University Voice: 416 736-2100 x66249 Fax: 416 736-5814 4700 Keele Street Web: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA
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:> On 8/26/2016 11:05 AM, Juan Ceccarelli Arias wrote: >> 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. >> > > 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. > >
Juan Ceccarelli Arias
2016-Aug-31 20:48 UTC
[R] Importint stata file and using value labels
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:> On 8/26/2016 11:05 AM, Juan Ceccarelli Arias wrote: > >> 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. >> >> > 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. > > > -- > Michael Friendly Email: friendly AT yorku DOT ca > Professor, Psychology Dept. & Chair, Quantitative Methods > York University Voice: 416 736-2100 x66249 Fax: 416 736-5814 > 4700 Keele Street Web: http://www.datavis.ca > Toronto, ONT M3J 1P3 CANADA >[[alternative HTML version deleted]]