Announcement

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

  • Problem with Reshape on Panel Data

    Hi all,
    My aim is to make variable id to be unique and I think reshape is the command instead of collapse.
    When I was tried with reshape from long to wide, error appear in output:
    Some error are:

    code : reshape wide hi06 hi07, i(id) j(hi01) string
    output: r(109); variable hi01 is numeric

    I did convert data hi01 to string
    command: tostring hi01, replace
    hi01 was byte now str1

    and did command : . reshape wide hi06 hi07, i(id) j(hi01) string
    output :
    (note: j = 1 3 8)
    values of variable hi01 not unique within id
    Your data are currently long. You are performing a reshape wide. You
    specified i(id) and j(hi01). There are observations within i(id) with the
    same value of j(hi01). In the long data, variables i() and j() together
    must uniquely identify the observations.

    long wide
    +---------------+ +------------------+
    | i j a b | | i a1 a2 b1 b2 |
    |---------------| <--- reshape ---> |------------------|
    | 1 1 1 2 | | 1 1 3 2 4 |
    | 1 2 3 4 | | 2 5 7 6 8 |
    | 2 1 5 6 | +------------------+
    | 2 2 7 8 |
    +---------------+
    Type reshape error for a list of the problem variables.
    r(9);

    I also did several combination to reshape, including dropping some variables that not really urgent for my analysis (especially drop variable with missing value), therefore the variables left are: id, hi01, hi06, but result almost the same either. Probably I do not really understand the reshape structure.
    Thanks in advance.

    [CODE]
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str1(hi01 hitype) byte(hi02 hi06 hi07 hi08x) str9 id
    "3" "." . 3 . . "001220001"
    "3" "." . 3 . . "001220002"
    "3" "." . 3 . . "001220003"
    "3" "." . 3 . . "001220004"
    "3" "." . 3 . . "001220005"
    "3" "." . 3 . . "001220011"
    "3" "." . 3 . . "001250001"
    "3" "." . 3 . . "001250002"
    "3" "." . 3 . . "001250003"
    "3" "." . 3 . . "001290001"
    "3" "." . 3 . . "001290002"
    "3" "." . 3 . . "001290003"
    "3" "." . 3 . . "002010001"
    "3" "." . 3 . . "002010002"
    "3" "." . 3 . . "002010003"
    "3" "." . 3 . . "002010004"
    "3" "." . 3 . . "002020003"
    "3" "." . 3 . . "002020007"
    "3" "." . 3 . . "002030001"
    "3" "." . 3 . . "002030002"
    "3" "." . 3 . . "002040001"
    "3" "." . 3 . . "002040002"
    "3" "." . 3 . . "002090001"
    "3" "." . 3 . . "002090002"
    "1" "A" 3 3 . . "002090003"
    "1" "D" 3 3 . . "002090003"
    "1" "C" 3 3 . . "002090003"
    "1" "B" 1 3 . . "002090003"
    "1" "V" 3 3 . . "002090003"
    "1" "C" 3 3 . . "002090006"
    "1" "D" 3 3 . . "002090006"
    "1" "A" 3 3 . . "002090006"
    "1" "B" 1 3 . . "002090006"
    "1" "V" 3 3 . . "002090006"
    "3" "." . 3 . . "002090007"
    "1" "D" 3 3 . . "002093102"
    "1" "V" 3 3 . . "002093102"
    "1" "A" 3 3 . . "002093102"
    "1" "C" 3 3 . . "002093102"
    "1" "B" 1 3 . . "002093102"
    "3" "." . 3 . . "002093202"
    "1" "D" 3 3 . . "002093301"
    "1" "V" 3 3 . . "002093301"
    "1" "A" 3 3 . . "002093301"
    "1" "C" 3 3 . . "002093301"
    "1" "B" 1 3 . . "002093301"
    "3" "." . 3 . . "002100001"
    "3" "." . 3 . . "002100002"
    "3" "." . 3 . . "002110001"
    "3" "." . 3 . . "002110002"
    "3" "." . 3 . . "002120001"
    "3" "." . 3 . . "002140001"
    "3" "." . 3 . . "002140002"
    "3" "." . 3 . . "002160001"
    "3" "." . 3 . . "002180003"
    "3" "." . 3 . . "002180004"
    "3" "." . 3 . . "002180005"
    "3" "." . 3 . . "002183101"
    "3" "." . 3 . . "002190001"
    "1" "B" 3 3 . . "002200001"
    "1" "A" 1 3 . . "002200001"
    "1" "V" 3 3 . . "002200001"
    "1" "C" 3 3 . . "002200001"
    "1" "D" 3 3 . . "002200001"
    "3" "." . 3 . . "002210001"
    "3" "." . 3 . . "002250001"
    "3" "." . 3 . . "002250002"
    "3" "." . 3 . . "002250007"
    "3" "." . 3 . . "002260001"
    "3" "." . 3 . . "002260002"
    "3" "." . 3 . . "002260005"
    "3" "." . 3 . . "002260006"
    "3" "." . 3 . . "002270001"
    "3" "." . 3 . . "002270002"
    "3" "." . 3 . . "002270003"
    "3" "." . 3 . . "002270004"
    "3" "." . 3 . . "002270006"
    "3" "." . 3 . . "002290001"
    "3" "." . 3 . . "002290002"
    "3" "." . 3 . . "002290006"
    "3" "." . 3 . . "002300001"
    "3" "." . 3 . . "002300006"
    "3" "." . 3 . . "002300011"
    "3" "." . 3 . . "003010001"
    "3" "." . 3 . . "003010002"
    "3" "." . 3 . . "003010005"
    "3" "." . 3 . . "003020002"
    "3" "." . 3 . . "003020003"
    "3" "." . 3 . . "003030001"
    "3" "." . 3 . . "003030004"
    "3" "." . 3 . . "003030005"
    "3" "." . 3 . . "003031201"
    "3" "." . 3 . . "003040002"
    "3" "." . 3 . . "003050001"
    "3" "." . 3 . . "003050002"
    "3" "." . 3 . . "003050004"
    "3" "." . 3 . . "003050006"
    "3" "." . 3 . . "003070002"
    "3" "." . 3 . . "003070005"
    "3" "." . 3 . . "003080001"

  • #2
    Thanks for your data example, but beyond the indication that id is an identifier I find this hard to follow. On the face of it hi01 looks similar to the other hi0* variables, but why is it string? Why Why do you regard it as a column identifier?

    Odds are that what you want would be much, much clearer if you used informative variable names and informative variable labels.

    Comment


    • #3
      Hi Nick Cox,
      Thanks for your reply and my apology for uninformative variables.
      I did your advice by convert back to numeric for hi01 and simplify the variables. After several attempts,I am able to made id as unique variable by dropped duplicates.
      Some step before use drop duplicates is using tag.
      Thanks.

      Comment

      Working...
      X