Announcement

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

  • Reshaping cross-section into longitudinal data

    Good morning,


    For my master thesis I have to analyze the impact of a treatment X at time t on an outcome Y at t+1.
    Currently, my dataset is cross-sectional having a column identifying only once the individual and all the other variables, collected both at time t and time t+1, not being distinguished by the time element.


    ID Xt Xt+1
    1 a b
    2 c d
    3 e f



    Therefore, I was wondering whether I have to reshape my data in order to have two rows for each individual in the dataset to obtain something like this:

    ID Xt Xt+1
    1 a .
    1 . b
    2 c .
    2 . d

    However, it is not clear to me which commands I should use on STATA to obtain the above results.


    Thank you





  • #2
    "Xt+1" cannot be a Stata variable name. You should start by naming [Xt Xt+1 Xt+2 ...] as [X0 X1 X2 ...]. Then just have an X variable and a time variable.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte ID str1(X0 X1)
    1 "a" "b"
    2 "c" "d"
    3 "e" "f"
    end
    
    reshape long X, i(ID) j(time)
    Res.:

    Code:
    . l, sepby(ID)
    
         +---------------+
         | ID   time   X |
         |---------------|
      1. |  1      0   a |
      2. |  1      1   b |
         |---------------|
      3. |  2      0   c |
      4. |  2      1   d |
         |---------------|
      5. |  3      0   e |
      6. |  3      1   f |
         +---------------+

    Comment


    • #3
      reshape to long, the Y variable should be a single variable, and identify t+1 as post and mark the treated.

      as Andrew demonstrates.

      Comment

      Working...
      X