Announcement

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

  • Difficulty reshaping data from wide to long format: variable id does not uniquely identify the observations

    The purpose is to make the panel data ready for regression analysis, so I want to reshape it from wide to long format.

    I tried the command:
    Code:
    reshape long pend, i(Kommunenummer) j(year)
    I have no idea how to fix this. The column "Kommunenummer" are the individual observations while pend is a variable and the years are from 2000 to 2023. I'm trying to assess the impact of the pandemic on commuting.
    Click image for larger version

Name:	error reshape long.png
Views:	1
Size:	200.2 KB
ID:	1752914



    The STATA file is attached below

    https://drive.google.com/file/d/1oGS...usp=share_link

    Any helpful inputs will be appreciated
    Last edited by Andrew Holm; 10 May 2024, 06:14.

  • #2
    Did you type
    Code:
     reshape error
    as recommended?

    Otherwise, type

    Code:
    duplicates list Kommunenummer
    as implied (a little indirectly) by the FAQ https://www.stata.com/support/faqs/d...d-time-values/

    One common problem is that you have a bundle of observations with missing values for commune number, as a side-effect of some spreadsheet nonsense.

    Otherwise you may be being bitten by some accidental duplication or typos.

    Your data aren't sorted by this variable. That's irrelevant to reshape but it makes a little difficult to see whether there are duplicates in the screenshot.

    Note. I (and many others) are reluctant to download Stata datasets on grounds explained in the FAQ Advice.

    Out of sight is a command that led to 2 missing values. That might be relevant.
    Last edited by Nick Cox; 10 May 2024, 06:43.

    Comment


    • #3
      Thank you @Nick Cox, the duplicates command worked, apparently the 2 last rows had missing values and were somehow counted, afterwards the reshape command transformed the data as desired. It seems the problem was deleting 2 rows from an Excel table and then importing that table into STATA.
      Last edited by Andrew Holm; 10 May 2024, 08:52.

      Comment

      Working...
      X