Announcement

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

  • forvalues loop issue for csdid regression

    Hello

    I have the following code that I am using to find the threshold value. I want to find the value for the headline cpi inflation rate beyond which I get insignificant results but my matrix keeps displaying the same values for coefficients and p-values from different iterations. How can I get different results for iterations at each `j'?

    Code:
    use "\\Client\H$\Desktop\data\mainfile.dta", clear
    drop if year_T>2011
    matrix results = J(11, 2, .)
    
    local row = 1
    
    forvalues j=90/100 {
        
        gen new`j' = hcpi_a > `j'
        bys country: egen new_new`j' = max(new`j')
        drop if new_new`j' == 1
        csdid hcpi_a, ivar(country_code) time(year) gvar(year_T)
        estat simple
    
        matrix results[`row', 1] = r(table)[1,1]
        matrix results[`row', 2] = r(table)[4,1]
        
        local row = `row' + 1
    }
    
    matrix list results
    My data looks like this:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int year str3 country float(hcpi_a treat year_T country_code)
    1980 "AFG" 13.4 0 0 1
    1981 "AFG" 22.2 0 0 1
    1982 "AFG" 18.2 0 0 1
    1983 "AFG" 15.9 0 0 1
    1984 "AFG" 20.4 0 0 1
    1985 "AFG"  8.7 0 0 1
    1986 "AFG" -2.1 0 0 1
    1987 "AFG" 18.4 0 0 1
    1988 "AFG" 27.5 0 0 1
    end

    Thank you!

  • #2
    nothing in the csdid line is indexed to j?

    Comment


    • #3
      Hi George Ford

      I tried putting the following but it didn't work:

      Code:
      csdid hcpi_a, ivar(country_code) time(year) gvar(year_T) if hcpi_a == `j'

      Comment


      • #4
        what are the "new" variables you create for?

        Comment


        • #5
          George Ford :

          I want to estimate if there is any significance at that particular level of `j' which is why I have created the new variables.

          Comment


          • #6
            It looks to me like you've dropped all countries that meet the hcpi_a > 90 threshold in the first round. Since 90 is smallest, there's nothing to drop after that so you're just running the same model over and over after 90.

            Need preserve/restore, or else "if" the csdid command (if you can) rather than drop countries.

            I'm not sure this does what you want. You are just tossing countries with extreme values, both controls and treated units.

            Comment


            • #7
              George Ford
              I understand and I have been trying to overcome that same issue. I have tried using preserve and restore and placing my dataset command also inside the loop. But it didn't give me a solution.
              Is there any way you can provide me with a solution or something I can look into and build upon?
              ​​​​​​​

              Comment


              • #8
                I don't understand this "I want to find the value for the headline cpi inflation rate beyond which I get insignificant results "

                This suggests there is something like a quadratic relationship, so significance is only found "in the middle".

                What exactly is your theory?

                What is the treatment?

                Does it occur at different times?
                Last edited by George Ford; 22 Mar 2023, 12:02.

                Comment


                • #9
                  George Ford

                  Sorry for not explaining properly.

                  Yes, I have a bunch of treatment countries and have different years of treatment for each of them which is why I am using csdid.
                  So, based on a certain smoothing approach when I drop countries, I get some significant results that inflation is indeed lower for those countries. the research question is whether a particular policy works or not. However, without doing any sort of smoothing, I want to find out beyond what level of cpi will I get insignificant results meaning that the policy wouldn't work at all.

                  Comment


                  • #10
                    So the treatment effect depends on the size of the outcome?

                    The same policy intervention when inflation is 10% does not exist when inflation is 100%?

                    I might start by dividing countries into "high" and "low" or "low, mid, high" and run them separately.

                    So use the "new" variable above to split your sample and estimate a csdid on new and ~new.



                    Comment


                    • #11
                      George Ford

                      I was able to solve it. I just had to include my data set inside the loop and not outside as I have shown in the above code. I am now getting the correct values in my matrix.

                      Thank you for your time and help.

                      Comment


                      • #12
                        Excellent. Fixed the drop `j' problem.

                        Comment

                        Working...
                        X