I'm really new on Stata and I'm trying to work with a panel data. I know that, to set a panel data, one uses xtset id year, but when I try to use this command Stata returns the error "repeated time values within panel (r451)". I know that this happens because I have the same id repeated in the same year (for instance Mark appears several times within 2011). It happens because in my panel, the same id works in several companies. My goal is to keep these multiple observations because I need it (so I must not remove duplicates). How can I do it? I have tried to do:
egen new_id= group (id firm)
but it doesn't work (xtset still gives me that error). Many thanks for your attention.
This usually occurs when multiple ID are repeated more than once in a panel. To solve this,
You may want to export your data to R and use the distinct function from dplyr package to remove the redundant rows.
Once you done you may export your data as .dta and then proceed to stata
Here is sample of using the distinct function
df_unik = df_final %>% distinct(year, country, .keep_all=TRUE)
In this case, df_final my data containing repeated rows, year and country are my panel identifier