Announcement

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

  • Changing list data to include a new column

    Hi, I asked this question in Cross Validated but they requested I move it here,

    I have a dataset of the form:

    YEAR ID Data
    year X 1 x_1
    year X 2 x_2
    year Y 1 y_1
    year Y 2 y_2
    ...

    I would like to put it in the form:

    YEAR ID Data_X Data_Y
    year 1 x_1 y_1
    year 2 x_2 y_2
    ...

    I feel like we want to make vectors somehow out of the years $X$ and $Y$, so that here the data set becomes a $2 \times 1$ vector, then take the transpose of it.

    A comment as an answer there said to use "dcast" in R, is there any equivalent command for this in Stata?

  • #2
    Sorry, no idea what dcast does in R.

    Concrete examples beat schematic examples. We give concrete advice on that in http://www.statalist.org/forums/help#stata -- which you were asked to read before posting.

    Your data imply four variables (not three), say. With some guesswork I am led to suggest the following example:

    Code:
    clear
    input YEAR str1 ID1 ID2 Data
    2014 X 1 12
    2015 X 2 34
    2014 Y 1 56
    2015 Y 2 78
    end
    reshape wide Data , i(YEAR ID2) j(ID1) string
    list
    
    
         +----------------------------+
         | YEAR   ID2   DataX   DataY |
         |----------------------------|
      1. | 2014     1      12      56 |
      2. | 2015     2      34      78 |
         +----------------------------+
    
    .
    Very possibly your example was intended to refer to just one year, and the same code should work for that.

    Comment


    • #3
      Hi, thank you very much, I've read the beginning guide now and will use concrete examples in the future.

      Comment

      Working...
      X