Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Reshaping Wide Unique Identifier not recognized

    Dear Statalist Forum,
    I have a problem with the following reshape command:

    Code:
    reshape wide value, i(country cpcountry  cpsector period) j(ins_pos_id)
    I get the following error:
    Code:
    values of variable ins_pos_id not unique within country cpcountry cpsector period
        Your data are currently long.  You are performing a reshape wide.  You specified i(country cpcountry
        cpsector period) and j(ins_pos_id).  There are observations within i(country cpcountry cpsector
        period) with the same value of j(ins_pos_id).  In the long data, variables i() and j() together must
        uniquely identify the observations.
    Now comes the interesting point.
    Using
    Code:
    egen id = group(country cpcountry  cpsector period ins_pos_id)
    isid id
    Tells me that the id does not give unique observations.
    However, I find that the ins_pos_id does cause a difference between observation one and two
    if I look at the data.
    In thefirst observation ins_pos_id is equal to 1 and in the second observation ins_pos_id the value is equal to 6.
    Ins_pos_id is codes different investment instruments.

    This is the Data.
    Code:
    input float id str27 country str51 cpcountry str34 cpsector str7 period float(ins_pos_id value)
      1 "5A: All reporting countries" "1C: International organisations" "A: All sectors" "1978-Q1" 1   -72.673
      2 "5A: All reporting countries" "1C: International organisations" "A: All sectors" "1978-Q1" 6   -72.673
      3 "5A: All reporting countries" "1C: International organisations" "A: All sectors" "1978-Q2" 1   152.314
      4 "5A: All reporting countries" "1C: International organisations" "A: All sectors" "1978-Q2" 6   152.314

    What is going wrong?
    I am using Stata 14 and I have Stata 16 available.

    Thank you very much
    and kind regards

    Alexander Marx

  • #2
    I don;t think I've ever met a problem where so many variables jointly are used to define a row identifier for reshape. I can't see that your data as glimpsed here is as yet fit for many Stata purposes, although the string date variable could be made useful. But the data example you've given doesn't, so far as I can see, show any problems as the identifiers are different.


    Code:
    duplicates report id ins_pos_id 
    duplicates list id ins_pos_id
    might help us and you.

    Comment


    • #3
      Thank you very much for your quick response Nick.
      Unfortunately I have got a dataset with some 100.000 observations,
      therefore the list command does not help a lot.

      I do believe that I dropped a variable on the way, which uniquely identifies the observation.
      I will check that again if I do not find anything I´ll come back to you.

      Comment


      • #4
        It's not list that I am recommending but duplicates. Typically lengthy output confirms that there is a problem and may indicate what it is.

        Comment

        Working...
        X