0
$\begingroup$

I tried to convert my data to panel data but i kept experiencing an error message. The data is in the form of likert scale. The error message was

duplicate couples (id-time) in resulting pdata.frame to find out which, use, e.g., table(index(your_pdataframe), useNA = "ifany") Also, i would like to conduct a probit and logit model with my data.

My data frame does not include duplicates but R Studio is assuming that they are duplicates. I do not want to remove any of my data. Can someone advise me on how to resolve the issue?. Or is there any way that i can make all my values unique without removing any of them?

Here are the functions that i used before trying to convert my data to panel data;

library(readxl) sample <- read_excel("Documents/sample.xlsx") View(sample) pdata.frame(sample) I was trying to convert my data to panel data but it did not work.

country 1 1 1 1 1 2 2 2 2 2 year 1 1 1 1 1 2 2 2 2 2 age 1 2 1 1 3 1 2 2 4 1 health 2 3 2 2 1 2 2 1 3 3 schooling 1 0 1 2 0 2 2 1 1 2

$\endgroup$
4
  • $\begingroup$ could you please post minimal working example so we can try to first replicate the problem? $\endgroup$
    – 1muflon1
    Mar 30 at 16:57
  • 1
    $\begingroup$ A quick glance says your data set does contain duplicates, there are 4 observations for country 1 in year 1. The other data doesn't matter. $\endgroup$ Mar 30 at 17:09
  • $\begingroup$ Please how do i solve the problem of the duplicates? $\endgroup$
    – musa
    Mar 30 at 18:00
  • 2
    $\begingroup$ The question about duplicates being a duplicate is a nice touch. $\endgroup$
    – Giskard
    Mar 30 at 20:40

1 Answer 1

1
$\begingroup$

As others have said, you should post a minimum working example (MWE) to help with troubleshooting.

If the unit of observation is "country", then you do have duplicates.

Once you know what variables you are indexing your panel data on, you can use something like this to drop duplicate observations:

index_vars <- c("var1","var2")
new_df <- df[!duplicated(df[, index_vars]), ]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.