Announcement

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

  • Drawing the IRF for 25 combinations in a loop form

    Hello, I try to estimate and draw a chart of IRF for 25 combinations based on this model :

    yi,t+k=𝛼ik+𝛾tk+𝛽k∆Ri,t+∑𝜗jk∆Ri,t−j+∑𝜃jkyi,t−j+𝜀tk
    that
    ∑𝜗jk∆Ri,t−j
    is from 1 to 5

    and also
    ∑𝜃jkyi,t−j
    is from 1 to 5


    ∆Ri,t
    is the shock

    I do not know how to solve it and draw the chart for 25 combinations in a loop form ( because it could be lag one versus lag one, lag one versus two ......, lag tow versus lag one, lag two versus lag two ....and so on)

    I hope I receive your guidance.


    Many thanks in advance.

    regards,



  • #2
    please help me.
    regards,

    Comment


    • #3
      If I understand your question, here's a starting point. You can try to rework this to suit your needs.

      Code:
      clear all
      
      tempfile temp
      save `temp', emptyok
      
      forvalues x = 1/5 {
          webuse lutkepohl2, clear
          tsset
          
          var dln_inv dln_inc dln_consump, lags(1/`x')
          irf create order`x', step(10) set(myirf`x', replace)
          use myirf`x'.irf, clear
          
          append using `temp'
          save `temp', replace
          erase myirf`x'.irf
      }
      
      use `temp', clear
      
      * as an example
      keep if response == "dln_inc" & impulse == "dln_consump"
      encode irfname, gen(lag_order)
      
      xtset lag_order step
      xtline oirf, overlay

      Comment


      • #4
        @Justin Niakamal thank you so much for your reply.
        my question is that I am dealing with the panel data from 1996-2019.

        yi,t+k = 𝛼i+𝛾t+ 𝛽∆Ri,t +∑𝜗j ∆Ri,t−j + ∑𝜃j yi,t−j + 𝜀t

        𝛽∆Ri,t is the shock
        ∑𝜗j ∆Ri,t−jis from 1 to 5

        ∑𝜃j yi,t−jis from 1 to 5

        I want to draw the chart for 25 combinations in a loop form ( because it could be lag one versus lag one, lag one versus two ......, lag tow versus lag one, lag two versus lag two ....and so on).

        your example really helps me, but the problem is that here "lags(1/`x')" are for all independent variables. I think for example of mine and for the "IRF" I should do another? I could not get different charts.

        I did in this way , but it is not correct,


        Code:
        clear
        foreach v in "ltotalfertility"  {
        foreach i in "d_dumrecession"    {
        forvalues x = 1/5               {    
        foreach vart in "0" "1" "2" "3" "4" "5" {
        cd "C:\Users\KHATEREH\Desktop\MyProject/`v'"
        use "C:\Users\KHATEREH\Desktop\fertility_xtscc.dta"   
        xi: statsby _b _se e(r2_a), clear:  xtscc f(`vart').`v' d_dumrecession l(1/`x')`i' l(1/`x')`v' i.year, fe
        irf create order`x'.irf , clear
        foreach var in d_dumrecession {
            gen t_`var' = _b_`var'/_se_`var'
            gen time = "obs`vart'"
        save `v'`vart'.dta, replace
            }
            } 
            }
            }    
            }
        I do not know how to solve it and draw it.


        many thanks,
        regards ,






        Last edited by Khati Zolfaghari; 16 Jan 2022, 12:29.

        Comment


        • #5
          I hope I receive your assistance soon . I need your help.

          Regards,

          Comment


          • #6
            Since you have panel data (I overlooked that in your notation) you should look into pvar (from the Stata Journal). I've not used xtscc (SSC), but it looks like it doesn't support IRFs as indicated by the post estimation commands. So one option is to use pvar -- throw your dummy variables exog(varlist) and save the data from pvarirf

            Comment


            • #7
              @Justin Niakamal Thank you so much for your reply. I am sharing my codes and, finally, it gives me at the end 25 charts of combination.

              Code:
              clear
              foreach   v in "totalfertility"         {
              forvalues x = 1/5                       {
              forvalues y = 1/5                       {                
              foreach vart in "0" "1" "2" "3" "4" "5" { 
              cd "C:\Users\KHATEREH\Desktop\MyProject/`v'"
              use "C:\Users\KHATEREH\Desktop\charts A\xtscc-correct-dataset.dta"   
              xi: statsby _b _se e(r2_a), clear: xtscc d`vart'`v' l(0/`y')dum_recession l(1/`x')d0`v' i.year,fe
              foreach var in dum_recession {
                  gen t_`var' = _b_`var'/_se_`var'
                  gen time = "obs`vart'" 
              save `y'`x'`v'`vart'.dta, replace
                  }
                  }
                  }    
                  }
                  }
              and then :
              Code:
              clear
              foreach v in  "totalfertility"  {
              forvalues x = 1/5               {
              forvalues y = 1/5               {        
              use "C:\Users\KHATEREH\Desktop\MyProject/`v'/`y'`x'`v'0.dta"
              foreach var in  "1" "2" "3" "4" "5" {
              append using  "C:\Users\KHATEREH\Desktop\MyProject/`v'/`y'`x'`v'`var'.dta"
              *drop _merge
              }
              gen date_string = substr(time, 4, 2)
              destring date_string, gen(year)
              
              keep  year  _b_dum_recession _se_dum_recession t_dum_recession 
              order  year  _b_dum_recession _se_dum_recession t_dum_recession 
              gen label="all"
              bysort label (year) : gen first = _n == _N-5
              **expand only the first obs
              expand 2 if first==1
              **** generate the new time variable
              bysort label (year) :gen time2 = _n-2
              ***recode the variables
              replace _b_dum_recession=0 if time2==-1
              replace _se_dum_recession=0 if time2==-1  
              replace t_dum_recession=0 if time2==-1  
              bysort label (year) : gen low = _b_dum_recession-(_se_dum_recession*1.645)
              bysort label (year) : gen high = _b_dum_recession+(_se_dum_recession*1.645)
              gen a=0 
              *a=0 is for charts  
              save "C:\Users\KHATEREH\Desktop\MyProject/`y'`x'`v'all.dta", replace
              }
              }
              }
              I am sharing this, maybe of intrest.

              Thanks a lot.

              Comment

              Working...
              X