exporting data to stata

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

exporting data to stata

Ivano
Hi,

I am new to R and I want to export data into Stata. Could somebody help with that? Thanks a lot.

This is the code I am using:


> setwd("D:/datasets/Seg-bcn/ESBD")
> data1 <- readRDS("r17045_ESDB_Habitatges_BDD_V_1_0.rds")
> library(foreign)
> write.dta(data="data1", file = "D:/datasets/data1.dta")
Error in write.dta(data = "data1", file = "D:/datasets/data1.dta") :
  The object "dataframe" must have class data.frame
> class (data1)
[1] "survey.design2" "survey.design"


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: exporting data to stata

Raja, Dr. Edwin Amalraj
Hi ,

library(foreign)
write.dta(data1,  "data1.dta")

should work. The file will be saved in the working directory.
Use
getwd()
to know the working directory.

Best wishes
Amalraj Raja

-----Original Message-----
From: R-help [mailto:[hidden email]] On Behalf Of rosario scandurra
Sent: 22 March 2018 07:47
To: [hidden email]
Subject: [R] exporting data to stata

Hi,

I am new to R and I want to export data into Stata. Could somebody help with that? Thanks a lot.

This is the code I am using:


> setwd("D:/datasets/Seg-bcn/ESBD")
> data1 <- readRDS("r17045_ESDB_Habitatges_BDD_V_1_0.rds")
> library(foreign)
> write.dta(data="data1", file = "D:/datasets/data1.dta")
Error in write.dta(data = "data1", file = "D:/datasets/data1.dta") :
  The object "dataframe" must have class data.frame
> class (data1)
[1] "survey.design2" "survey.design"


[[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.


The University of Aberdeen is a charity registered in Scotland, No SC013683.
Tha Oilthigh Obar Dheathain na charthannas clàraichte ann an Alba, Àir. SC013683.
______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: exporting data to stata

Michael Dewey-3
In reply to this post by Ivano
Dear Rosario

Your object called data1 is, as you showed us, of the wrong class. You
therefore need to convert it in some way although i suspect you will
then use the survey information.

Michael.

On 22/03/2018 07:46, rosario scandurra wrote:

> Hi,
>
> I am new to R and I want to export data into Stata. Could somebody help with that? Thanks a lot.
>
> This is the code I am using:
>
>
>> setwd("D:/datasets/Seg-bcn/ESBD")
>> data1 <- readRDS("r17045_ESDB_Habitatges_BDD_V_1_0.rds")
>> library(foreign)
>> write.dta(data="data1", file = "D:/datasets/data1.dta")
> Error in write.dta(data = "data1", file = "D:/datasets/data1.dta") :
>    The object "dataframe" must have class data.frame
>> class (data1)
> [1] "survey.design2" "survey.design"
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.
>

--
Michael
http://www.dewey.myzen.co.uk/home.html

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: exporting data to stata

Ista Zahn
In reply to this post by Raja, Dr. Edwin Amalraj
On Thu, Mar 22, 2018 at 4:52 AM, Raja, Dr. Edwin Amalraj
<[hidden email]> wrote:
> Hi ,
>
> library(foreign)
> write.dta(data1,  "data1.dta")
>
> should work.


I don't think so:

> library(foreign)
> example(svydesign)
> write.dta(dstrat, "~/Downloads/foo.dta")
Error in write.dta(dstrat, "~/Downloads/foo.dta") :
  The object "dataframe" must have class data.frame


The file will be saved in the working directory.

> Use
> getwd()
> to know the working directory.
>
> Best wishes
> Amalraj Raja
>
> -----Original Message-----
> From: R-help [mailto:[hidden email]] On Behalf Of rosario scandurra
> Sent: 22 March 2018 07:47
> To: [hidden email]
> Subject: [R] exporting data to stata
>
> Hi,
>
> I am new to R and I want to export data into Stata. Could somebody help with that? Thanks a lot.
>
> This is the code I am using:
>
>
>> setwd("D:/datasets/Seg-bcn/ESBD")
>> data1 <- readRDS("r17045_ESDB_Habitatges_BDD_V_1_0.rds")
>> library(foreign)
>> write.dta(data="data1", file = "D:/datasets/data1.dta")
> Error in write.dta(data = "data1", file = "D:/datasets/data1.dta") :
>   The object "dataframe" must have class data.frame
>> class (data1)
> [1] "survey.design2" "survey.design"
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.
>
>
> The University of Aberdeen is a charity registered in Scotland, No SC013683.
> Tha Oilthigh Obar Dheathain na charthannas clàraichte ann an Alba, Àir. SC013683.
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: exporting data to stata

ajdamico
hi, you can export the dataset from an R  survey design to stata with

install.packages('survey')
library(survey)
library(foreign)
write.dta( data1$variables , "c:/path/to/file.dta" )

then type "data1" into the R console to look at the weight, id/cluster,
strata, and fpc variables to use for the "svyset" command




On Thu, Mar 22, 2018, 12:33 PM Ista Zahn <[hidden email]> wrote:

> On Thu, Mar 22, 2018 at 4:52 AM, Raja, Dr. Edwin Amalraj
> <[hidden email]> wrote:
> > Hi ,
> >
> > library(foreign)
> > write.dta(data1,  "data1.dta")
> >
> > should work.
>
>
> I don't think so:
>
> > library(foreign)
> > example(svydesign)
> > write.dta(dstrat, "~/Downloads/foo.dta")
> Error in write.dta(dstrat, "~/Downloads/foo.dta") :
>   The object "dataframe" must have class data.frame
>
>
> The file will be saved in the working directory.
> > Use
> > getwd()
> > to know the working directory.
> >
> > Best wishes
> > Amalraj Raja
> >
> > -----Original Message-----
> > From: R-help [mailto:[hidden email]] On Behalf Of rosario
> scandurra
> > Sent: 22 March 2018 07:47
> > To: [hidden email]
> > Subject: [R] exporting data to stata
> >
> > Hi,
> >
> > I am new to R and I want to export data into Stata. Could somebody help
> with that? Thanks a lot.
> >
> > This is the code I am using:
> >
> >
> >> setwd("D:/datasets/Seg-bcn/ESBD")
> >> data1 <- readRDS("r17045_ESDB_Habitatges_BDD_V_1_0.rds")
> >> library(foreign)
> >> write.dta(data="data1", file = "D:/datasets/data1.dta")
> > Error in write.dta(data = "data1", file = "D:/datasets/data1.dta") :
> >   The object "dataframe" must have class data.frame
> >> class (data1)
> > [1] "survey.design2" "survey.design"
> >
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [hidden email] 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.
> >
> >
> > The University of Aberdeen is a charity registered in Scotland, No
> SC013683.
> > Tha Oilthigh Obar Dheathain na charthannas clàraichte ann an Alba, Àir.
> SC013683.
> > ______________________________________________
> > [hidden email] 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.
>
> ______________________________________________
> [hidden email] 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.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.