Announcement

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

  • Panel Data Analysis: How to calculate first-differences regressions only in certain transitions?

    Hi Statalist,

    I am currently working with a panel dataset that contains grade levels (K1 to K4) (variable "grade_self"). My outcome of interest is "GPA" (values 1 to 5) and my treatment variable is "treatment" (values 0 and 1). I want to use the "regress" command to calculate first-differences between two consecutive grade levels. Currently my regression command (without controls) looks like this:

    Code:
    reg D.(GPA treatment), noconstant
    For a sub-analysis, I want to calculate the treatment effect only for certain cases. For this purpose, I have created a new variable named "matched":

    Code:
    bys ID_t (wave): gen matched = .
    bys ID_t (wave): replace matched = 1 if ((L.class_size_teacher - L.number_repeater_removals) == class_size_teacher) & ((L.grade_self + 1) == grade_self) & !missing(class_size_teacher, L.class_size_teacher, L.number_repeater_removals, LID)
    bys ID_t (wave): replace matched = 0 if F.matched==1 & matched==.
    With this variable, I marked some of the classes in certain grade levels with a 1. (The condition for this is that the number of removed class repeaters matches the observed change in class size). Classes can potentially receive a 1 at any grade level above K1 and more than once. I have coded it so that classes receive a 0 in the corresponding previous year before they are marked with "1" (if they are not marked with "1" already) and would now like to calculate the first-difference from 0 to 1. However, it can happen that "1->0" transitions occur in the panel data set. For example:

    Class A:
    K1 0
    K2 1
    K3 0
    K4 1
    In this example, it is important to me that Stata only calculates the first-difference between K1 and K2 (0->1) and the first-difference between K3 and K4 (0->1). However, no first-difference between K2 and K3 (1->0) should be calculated. However, I also want Stata to calculate the first-difference between two grade levels of a class that both receive a 1 in the "matched" variable, as in Class B:

    Class B:
    K1 .
    K2 0
    K3 1
    K4 1
    So in class B, I would like to calculate first-differences between K2 and K3, and between K3 and K4.


    In summary, I want to analyze all "0->1" and all "1->1" transitions, but never a "1->0" transition. My question is how I can implement this in Stata. I am very grateful for any help!






  • #2
    Any advice on this please? Unfortunately, I still have not found a solution and am very grateful for help!

    Comment


    • #3
      I do not completely follow your overall approach, but for the technical coding question, how about something like this. Since I don't know all your variable names or exactly how you want things coded, I left it generic, but should be easy enough to modify for your needs.


      Code:
      by some_sorting_variable: gen difference01=1 if variable[_n]==0 & variable[_n+1]==1
      
      by some_sorting_variable: gen difference11=0 if variable[_n]==1 & variable[_n+1]==1

      Comment

      Working...
      X