Questions tagged [r-haven]

The `haven` package for `R`

118 questions
1
vote
1 answer

How to extract just one of classes of object with multiple classes

Say I have a tibble named `a'. It has three classes: class(a) "tbl_df" "tbl" "data.frame" How can I extract just one of these classes? a$data.frame does not work. Another example is a haven_labelled object, b which has three…
bill999
  • 2,209
  • 7
  • 44
  • 78
1
vote
1 answer

Saving .dta: data frame with very long strings using R

I have a df with multiple variables, some are very long strings with up to 4500 characters. I would like to export this database as a .dta file. I try to save it using haven's write_dta() function, but I get the following error message: Error in…
Alex
  • 911
  • 4
  • 14
1
vote
1 answer

"Error: Can't convert to character"

My student and I both loaded the same dataset, installed the same packages, and were running the same code. When I run "frq" I get a frequency table and the variable is labeled as "numeric." When my student runs the same code, she gets "Error: Can't…
mt646
  • 11
  • 1
1
vote
2 answers

How to create a ggplot when the answers are FALSE or TRUE?

How can I create a plot with ggplot when my answers are TRUE or FALSE? This is my code: t.obese<-master1%>% filter(Income>0,obese==TRUE)%>% select(Income,obese) > head(t.obese) Income obese 1 21600 TRUE 2 4000 TRUE 3 12720 TRUE 4…
Lin
  • 43
  • 6
1
vote
1 answer

Can't convert dataframe to Stata using foreign or haven

I have a dataframe that I am trying to save as stata .dta file. I tried both haven and foreign packages but I get the fllowing errors: write_dta(df,"C:/Users/../df.dta") I get an error: Error in write_dta_(data, normalizePath(path, mustWork =…
jayjunior
  • 67
  • 5
1
vote
1 answer

Recoding one hevan_labelled variable

I tried to recode one variable of a dataset of a complex survey. I have tried dplyr::recode function. occup<-recode(sv$v717, c(0 )='0'; c(1, 2, 3 )='1'; c(4 )='2'; c(8, 9 )='3'; c(96, 98)='98'") Earlier I did same way successfully. However, this…
1
vote
2 answers

Writing failure: A provided name contains an illegal character. Error while saving R data into Stata format

I am using haven package to write the R dataset into Stata format. This is the error I am getting. write_dta(road_panel, "road_panel.dta", version = 14, label = attr(data,"label")) Error in write_dta_(data, normalizePath(path, mustWork = FALSE),…
Fuser
  • 23
  • 5
1
vote
1 answer

Getting a subset error I did not get two months ago when running logistic regression (svyglm) on survey data (SPSS dataset)

I re-run script that previously worked with no errors about two months ago. I used the haven package to upload an (non-public and proprietary) SPSS dataset and the survey package to analyze complex survey data. Now, however, when I run even a simple…
S. Kim
  • 13
  • 5
1
vote
1 answer

`ggeffect` or `Effect`cannot estimate marginal effects in model after checking factor levels and missing data

Using data imported with haven from a dataset that includes labels, I cannot get marginal effects using ggeffect() from the package ggeffects or Effect() from the package effects When using these functions an error gets prompted, although having…
Crimc
  • 157
  • 13
1
vote
1 answer

Error when estimating random effects model with plm package when haven is loaded

I have a weird problem when estimating a random effects with the plm package in R. Here is a link to a dput of part of my data: https://pastebin.com/raw/mTdh26dg My code is: library(plm) library(haven) pmales <- pdata.frame(males_part, index =…
avs
  • 492
  • 4
  • 10
1
vote
1 answer

How do I add SAS/SPSS-format labels stored as a .txt file to R?

I have a large survey that I am working with. The main survey data is stored as a CSV file. The variable and value label files are included in both SAS-format as well as SPSS-format, but stored as TXT files. I have seen that there are several…
anguyen1210
  • 353
  • 4
  • 15
1
vote
1 answer

How do I use mutate_at with set_value_labels to change the value labels of multiple variables?

How do I set the value labels for multiple variables in a data frame imported from SPSS via haven. This produces variables of the haven_labelled class. I am trying to set the value labels with the [labelled][1] package . #Fake…
spindoctor
  • 1,359
  • 1
  • 11
  • 27
1
vote
0 answers

What is the best way to treat labelled variables imported with haven?

I have about 15 SPSS election studies files saved as .sav files. My group and I will be recoding about 10 variables for each study to run some logistic regressions. I have used haven() to import all the files, so it looks like all the variables are…
spindoctor
  • 1,359
  • 1
  • 11
  • 27
1
vote
1 answer

Dynamically create value labels with haven::labelled, follow-up

Follow-up question to Dynamically create value labels with haven::labelled, where akrun provided a good answer using deframe. I am using haven::labelled to set value labels of a variable. The goal is to create a fully documented dataset I can…
oskjerv
  • 91
  • 5
1
vote
1 answer

R haven: accessing column label from imported SPSS file

I have a dataset in SPSS that I am reading into R using the 'haven' library df <- structure(list(SC155Q09HA = structure(c(2, 1, 1, 2, 1, 2, 3, 4, 3, 1), label = "School's capacity using digital devices: An effective online learning support…
pluke
  • 2,710
  • 5
  • 38
  • 60