Announcement

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

  • Panel Data Conditional Difference

    I have a panel dataset. I want to calculate the difference in value for a particular varlist on the condition that the variable value is equal to zero at either t or t-1. I'll give an example of what I hope to get.


    X[t-1] 0 3 - -
    X[t] 3 5 3 -
    Y[t-1] 6 5 - -
    Y[t] 4 0 - 5
    Z[t-1] 6 5 - -
    Z[t] 8 9 - -



    So the difference is only taken for changes to and from zero i.e. D.Var_A or D.Var_B.




    For changes between values other than zero, it doesn't really matter if they are represented by a - or a 0.




    Does this make sense? I always find it difficult to articulate a problem like this.




    What's the best way to go about this?

  • #2
    It seems unlikely that your data is organized the way you show it in your table. And if it is, you are likely to find it extremely difficult to work with. Please use the -dataex- command and show an actual example of your data. If you are running version 15.1 or a fully updated version 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    When asking for help with code, always show example data. When showing example data, always use -dataex-.

    Comment

    Working...
    X