Announcement

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

  • Why does Stata not reshape?

    Hi, Stata won't reshape my dataset. I am sure I am missing something, but I have the following dataset:

    Click image for larger version

Name:	Data.PNG
Views:	1
Size:	19.3 KB
ID:	1750146


    The code

    Code:
    reshape long EU EA DE FR IT ES AT BE FI IE LU NL PT,  i(t) j(country) string
    doesn't work and Stata says "no xij variables found. You typed something like reshape wide a b, i(i) j(j). reshape looked for existing variables named a# and b# but could not find any."

    Does that mean I somehow have to number these variables? How? They are just country codes.

    Thank you!

  • #2
    No, numbering those variables won't help. But the principle to remember is that the list that follows -reshape long- is not a list of variable names. It is a list of stubs, which, when supplemented with other material become variable names in your data set. The problem is that you listed variable names. You need to extract from them what they have in common, and express that in the -reshape long- command, and then leave it to -reshape- to extract the variable parts (EU EA, etc.) from there. But, of course, there is nothing these all have in common. So you need to give them something in common.

    Code:
    rename (EU EA DE FR IT ES AT BE FI IE LU NL PT) v=
    reshape long v, i(t) j(country) string
    You will now have panel data with t and country variables. The country variable will taken the values "EU", "EA", etc. And the variable v will contain the values that were originally in the EU EA... variables. Now, I recommend that you -v- to something that describes or at least suggests what the values in that variable actually represent.

    Comment


    • #3
      Great; I wasn't aware of the "v="-way of renaming variables. Much more elegant. Thank you!

      Comment

      Working...
      X