Announcement

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

  • Panel Data: Splitting a variable in positive and negative, running the same regression

    Hello everybody,

    let me get this out first: I am sure the seasoned Stata experts under you will laugh at me; rightfully so, my question is trivial.

    I am new to Stata and currently writing my master thesis.
    For this reason I want to take an exisiting dataset (dta data.dta and their do file do file.do are in the attachements), split the Oil Price Shock-variable, which is petro_nx_index_growth in positive shocks and negative shocks and run the same regressions afterwards.

    Unclear is for me, if or where in the split variables the 0s need to be (I tried both and failed twice) or how I split the variable in general...
    I am experimenting with the code for that, currently I have:

    set memory 100m
    tab ccode, gen(Iccode)
    tab year, gen(time)

    xtset ccode year, yearly

    * Try to split the Oil Price Shocks into positive an negative shocks


    gen pos_petro_nx_index_growth = petro_nx_index_growth if petro_nx_index_growth >= 0
    gen neg_petro_nx_index_growth = petro_nx_index_growth if petro_nx_index_growth <= 0


    gen a_pos_petro_nx_index_growth = petro_nx_index_growth if petro_nx_index_growth > 0
    gen a_neg_petro_nx_index_growth = petro_nx_index_growth if petro_nx_index_growth < 0


    *Table 2 with split shocks

    *With 0s in both

    eststo clear

    eststo mod1: quietly xtreg D.polity2 L(0/2).pos_petro_nx_index_growth L(0/2).neg_petro_nx_index_growth time* if D.exconst2!=. &growth!=., fe cluster(ccode)
    eststo mod2: quietly xtreg D.exconst2 L(0/2).pos_petro_nx_index_growth L(0/2).neg_petro_nx_index_growth time* if growth!=. ,fe cluster(ccode)
    eststo mod3: quietly xtreg D.exrec2 L(0/2).pos_petro_nx_index_growth L(0/2).neg_petro_nx_index_growth time* if growth!=. , fe cluster(ccode)
    eststo mod4: quietly xtreg D.polcomp2 L(0/2).pos_petro_nx_index_growth L(0/2).neg_petro_nx_index_growth time* if growth!=., fe cluster(ccode)


    esttab mod? using test1.txt, replace nonotes nogap drop(time* _cons) star( * 0.1 ** 0.05 *** 0.01 )

    *Without 0s

    eststo clear


    eststo mod1: quietly xtreg D.polity2 L(0/2).a_pos_petro_nx_index_growth L(0/2)a_neg_petro_nx_index_growth time* if D.exconst2!=. &growth!=., fe cluster(ccode)
    eststo mod2: quietly xtreg D.exconst2 L(0/2).a_pos_petro_nx_index_growth L(0/2).a_neg_petro_nx_index_growth time* if growth!=. ,fe cluster(ccode)
    eststo mod3: quietly xtreg D.exrec2 L(0/2).a_pos_petro_nx_index_growth L(0/2).a_neg_petro_nx_index_growth time* if growth!=. , fe cluster(ccode)
    eststo mod4: quietly xtreg D.polcomp2 L(0/2).a_pos_petro_nx_index_growth L(0/2).a_neg_petro_nx_index_growth time* if growth!=., fe cluster(ccode)


    esttab mod? using test2.txt, replace nonotes nogap drop(time* _cons) star( * 0.1 ** 0.05 *** 0.01 )

    I have to stay, that I am gratefull for any help on this regard.

    Greetings and have a great day,
    Leon
    Attached Files

  • #2
    Leon:
    I'm probably missing out on something here, but ho
    Code:
    gen pos_petro_nx_index_growth = petro_nx_index_growth if petro_nx_index_growth>= 0
    gen neg_petro_nx_index_growth = petro_nx_index_growth if petro_nx_index_growth <=0
    could live together?
    Shouldn't it be:
    Code:
    gen pos_petro_nx_index_growth = petro_nx_index_growth if petro_nx_index_growth >= 0
    gen neg_petro_nx_index_growth = petro_nx_index_growth if petro_nx_index_growth < 0
    Kind regards,
    Carlo
    (Stata 18.0 SE)

    Comment


    • #3
      Hi Carlo

      Thank you for the swift response.
      Yes, they could live together, but it didnt work out in the regressions so not really...

      I tried you're part code:

      gen pos_petro_nx_index_growth = petro_nx_index_growth if petro_nx_index_growth >= 0
      gen neg_petro_nx_index_growth = petro_nx_index_growth if petro_nx_index_growth < 0

      eststo mod1: quietly xtreg D.polity2 L(0/2).pos_petro_nx_index_growth L(0/2).neg_petro_nx_index_growth time* if D.exconst2!=. &growth!=., fe cluster(ccode)
      eststo mod2: quietly xtreg D.exconst2 L(0/2).pos_petro_nx_index_growth L(0/2).neg_petro_nx_index_growth time* if growth!=. ,fe cluster(ccode)
      eststo mod3: quietly xtreg D.exrec2 L(0/2).pos_petro_nx_index_growth L(0/2).neg_petro_nx_index_growth time* if growth!=. , fe cluster(ccode)
      eststo mod4: quietly xtreg D.polcomp2 L(0/2).pos_petro_nx_index_growth L(0/2).neg_petro_nx_index_growth time* if growth!=., fe cluster(ccode)

      esttab mod? using bob.txt, replace nonotes nogap drop(time* _cons) star( * 0.1 ** 0.05 *** 0.01 )

      and my result was: no observations r(2000);

      How do you write your code in a gray box? ^^

      Kind regards,
      Leon
      Last edited by Leon Probst; 08 Jun 2023, 11:02.

      Comment


      • #4
        Leon:
        have you already checked that r(2000) does not depend on -L.- operator and/or the -if- clauses?
        Kind regards,
        Carlo
        (Stata 18.0 SE)

        Comment


        • #5
          See https://www.statalist.org/forums/help#stata 12.3 for the use of CODE delimiters in this form

          Code:
          * this is a comment 
          sysuse auto.dta

          Comment


          • #6
            It appears you've generated missing data for the pos and neg variables, so when you combine them you have no data. I think it's common in these cases to define a dummy variables indicating positive or negative amounts. But these need to be defined for all observations. Then, interact each of these with the original variable.

            Comment


            • #7

              Hello Carlo!

              Yes, I tried dropping the lagged operator and the if clauses; that did not do the trick.
              The only thing that worked for me is using only positive OR negative shocks, but that is not what I wanted...

              Originally posted by Jeff Wooldridge View Post
              It appears you've generated missing data for the pos and neg variables, so when you combine them you have no data. I think it's common in these cases to define a dummy variables indicating positive or negative amounts. But these need to be defined for all observations. Then, interact each of these with the original variable.
              Hello Jeff,

              thank you for your tip.
              While I am quite unsure on how to use dummies I gave it my best shot:

              Code:
              gen pos_shock = 0
              replace pos_shock = 1 if petro_nx_index_growth > 0
              
              xtreg D.polity2 L(0/2).c.petro_nx_index_growth#i.pos_shock time* if D.exconst2!=. &growth!=., fe  cluster(ccode)
              xtreg D.exconst2  L(0/2).c.petro_nx_index_growth#i.pos_shock time* if growth!=.  ,fe cluster(ccode)
              xtreg D.exrec2  L(0/2).c.petro_nx_index_growth#i.pos_shock time* if growth!=. , fe cluster(ccode)
              xtreg D.polcomp2  L(0/2).c.petro_nx_index_growth#i.pos_shock time* if growth!=., fe  cluster(ccode)
              I could make another dummy for negative shocks, but I have the dummy trap in mind.
              If I do it the way you recommend I do not get an error message, but I dont quite know, how to interpret this and distinguish between positive and negative shock effects.

              Kind regards,
              Leon
              Last edited by Leon Probst; 09 Jun 2023, 08:55.

              Comment


              • #8
                Code:
                gen pos_shock = 0
                replace pos_shock = 1 if petro_nx_index_growth >= 0
                gen neg_shock = 0
                replace neg_shock = 1 if petro_nx_index_growth < 0
                xtreg D.polity2 L(0/2).c.petro_nx_index_growth#i.pos_shock L(0/2).c.petro_nx_index_growth#i.neg_shock time* if D.exconst2!=. &growth!=., fe cluster(ccode

                Comment


                • #9
                  Originally posted by Jeff Wooldridge View Post
                  Code:
                  gen pos_shock = 0
                  replace pos_shock = 1 if petro_nx_index_growth >= 0
                  gen neg_shock = 0
                  replace neg_shock = 1 if petro_nx_index_growth < 0
                  xtreg D.polity2 L(0/2).c.petro_nx_index_growth#i.pos_shock L(0/2).c.petro_nx_index_growth#i.neg_shock time* if D.exconst2!=. &growth!=., fe cluster(ccode
                  Trying this code gives me positive shock values, but no values for the negative shock interaction term.
                  I tried dropping the lags and the if statement, to no avail.

                  If you create a pos_shock and a neg_shock, there is perfect correlation between the two variables. Is that a problem?
                  And would it be sensible to include one ## so the petro_nx_index_growth (oil price shock) is also considered in the regression... Or is it covered when adding both interaction terms?

                  Thank you for your help, I really appreciate it!
                  Best wishes, Leon

                  Comment


                  • #10
                    Being back on topic, would splitting it like this work or is there an oversight by me?

                    Code:
                    gen pos_shock = cond(petro_nx_index_growth > 0, petro_nx_index_growth, 0)
                    gen neg_shock = cond(petro_nx_index_growth < 0, abs(petro_nx_index_growth), 0)
                    
                    xtreg D.polity2 L(0/2).pos_shock L(0/2).neg_shock time* if D.exconst2!=. &growth!=., fe cluster(ccode)

                    Comment


                    • #11
                      Leon: Replace i. with c.

                      Comment

                      Working...
                      X