Announcement

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

  • Converting data into Long form

    Hi everyone! I have a dataset in wide for, I want to convert it into long form. Here is an example of my dataset:

    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long hhid byte mid int(child_mauzaid1 child_mauzaid2) byte(child_schoolid1 child_schoolid2) long(child_teachercode1 child_teachercode2)
        . . 1 1 1 1 10104 10103
        . . 1 1 1 1 10104 10103
        . . 1 1 1 1 10104 10103
        . . 1 1 1 1 10104 10103
        . . 1 1 1 1 10104 10103
        . . 1 1 1 1 10104 10103
        . . 1 1 1 1 10104 10103
        . . 1 1 1 1 10104 10103
        . . 1 1 1 1 10104 10103
    62559 6 1 1 1 1 10104 10103
        . . 1 1 1 1 10104 10103
        . . 1 1 1 1 10104 10103
        . . 1 1 1 1 10104 10103
        . . 1 1 1 1 10104 10103
        . . . 1 . 1     . 10103
        . . . 1 . 1     . 10103
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
    62419 3 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
    62420 7 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 1 2 2 10205 10205
        . . 1 . 2 . 10205     .
        . . 1 1 2 2 10205 10205
        . . . 1 . 2     . 10205
        . . . 1 . 2     . 10205
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
        . . . . . .     .     .
    end
    I need to merge this dataset with another and I want to keep hhid and mid but the problem is that if I include these variables in my "reshape long...." ,I get an error that xij variables not found. Unlike the other variables hhid and mid don't change over the year. Please tell me how I should convert my dataset and keep hhid and mid.

  • #2
    Well, you can get this data into long layout this way:
    Code:
    gen long obs_no = _n
    reshape long child_mauzaid child_schoolid child_teachercode, i(obs_no) j(_j)
    But it's very peculiar data. You have a large number of observations with missing value on all variables. It's hard to imagine that they are useful in any way, and they are certainly going to make it difficult to merge this data set with anything else.

    I also don't understand your remark about hhid and mid not changing over the year. There are no time variables in your example data, so this doesn't make any sense to me.

    In the future, when you are having trouble with a command, it is important to show both the exact command (not just "reshape long..." which leaves all the important parts unspecified), not just the error message. In this case, I think I understood what the problem is, but you don't want to rely on people being able to guess what went wrong.

    Comment


    • #3
      Yes, this is the problem, thanks for the help! next time I will show the full command

      Comment

      Working...
      X