Announcement

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

  • Panel data set seperating IDs based on a variable for subsample analysis

    Der Stata list,


    I need to separate IDs of a panel dataset for subsample analysis based on values they have for a perticular variable ( say for an example you want to seperate goods based on price increases and decreases).
    An example of what I need is below. (
    Year ID Variable
    1990 1 1
    1990 2 23
    1990 3 5
    1990 4 -4
    1990 5 0
    1990 6 .
    1991 1 4
    1991 2 6
    1991 3 0
    1991 4 45
    1991 5 0
    1991 6 0
    1992 1 0
    1992 2 3
    1992 3 -3
    1992 4 0
    1992 5 0
    1992 6 .
    Criteria
    1) see what IDs have (at least ) one positive value throughout the panel (e.g IDs 1,2,3,4)
    2) see what IDs have (at least ) one negative value throughout the sample (e.g IDs 4 and 3)
    3) separate (create sub samples) above 1) and 2) IDs by providing them separate identifiers (probably by creating another variable)

    I appreciate if you could help me
    Last edited by krishantha Ainsworth; 14 Mar 2022, 09:05.

  • #2
    Code:
    egen crit1 = max(variable>0 & variable<.), by(id)
    egen crit2 = max(variable<0) ,by(id)
    egen group = group(crit1 crit2)

    Comment


    • #3
      Thank you so much Øyvind . One other question I have is how can I run a regression for both groups, those who increase and decrease ? If I run it as
      Code:
       regress y x if variable < 0 (or variable >0)
      does it satisfy my objective ? On the other hand what if
      I run them for if crit1/crit2 ==1?

      Comment


      • #4
        to restrict the sample to those who increase and decrease,
        Code:
        regress y x if crit1==1 & crit2==1
        or, equivalently,
        Code:
        regress y x if group==3

        Comment

        Working...
        X