Announcement

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

  • #16
    Code:
    sysuse auto, clear
    reg price mpg c.mpg#(c.weight c.length c.foreign) , noconstant
    predict pfit , xb
    gen pfitalt = _b[mpg]*mpg + _b[c.mpg#c.weight]*mpg*weight+_b[c.mpg#c.length]*mpg*length 
    gen newvar = _b[c.mpg#c.weight]*mpg*weight+_b[c.mpg#c.length]*mpg*length 
    gen newvaralt = pfit-_b[mpg]*mpg

    Comment


    • #17
      cancel that. error.
      Last edited by George Ford; 04 Nov 2021, 13:04. Reason: error/deleted

      Comment


      • #18
        A start (thoughts welcome).

        Code:
        sysuse auto, clear
        
        capture program drop myprog
        program define myprog, rclass
            reg mpg weight c.weight#(c.length c.foreign) , noconstant
            capture drop gr
            gen gr = _b[c.weight#c.length]*weight*length+_b[c.weight#c.foreign]*weight*foreign  
            reg price trunk gr
            return scalar t_trunk = (_b[trunk]-b_trunk)/_se[trunk]
            return scalar t_gr = (_b[gr]-b_gr)/_se[gr]
            return scalar t_cons = (_b[_cons]-b_cons)/_se[_cons]
        end
        
        reg mpg weight c.weight#(c.length c.foreign) , noconstant
        capture drop gr
        gen gr = _b[c.weight#c.length]*weight*length+_b[c.weight#c.foreign]*weight*foreign
        reg price trunk gr
        scalar b_trunk = _b[trunk]
        scalar b_gr = _b[gr]
        scalar b_cons = _b[_cons]
        
        bootstrap t_trunk=r(t_trunk) t_gr=r(t_gr) t_cons=r(t_cons), reps(100) seed(12345) saving(bs_t, replace): myprog
        preserve
        use bs_t, replace
        centile t_trunk, centile(2.5, 97.5)
        centile t_gr, centile(2.5, 97.5)
        centile t_cons, centile(2.5, 97.5)
        gen t_abs_trunk = abs(t_trunk)
        gen t_abs_gr = abs(t_gr)
        gen t_abs_cons = abs(t_cons)
        centile t_abs_trun t_abs_gr t_abs_cons, centile(95)
        restore

        Comment


        • #19
          Originally posted by George Ford View Post
          A start (thoughts welcome).

          Code:
          sysuse auto, clear
          
          capture program drop myprog
          program define myprog, rclass
          reg mpg weight c.weight#(c.length c.foreign) , noconstant
          capture drop gr
          gen gr = _b[c.weight#c.length]*weight*length+_b[c.weight#c.foreign]*weight*foreign
          reg price trunk gr
          return scalar t_trunk = (_b[trunk]-b_trunk)/_se[trunk]
          return scalar t_gr = (_b[gr]-b_gr)/_se[gr]
          return scalar t_cons = (_b[_cons]-b_cons)/_se[_cons]
          end
          
          reg mpg weight c.weight#(c.length c.foreign) , noconstant
          capture drop gr
          gen gr = _b[c.weight#c.length]*weight*length+_b[c.weight#c.foreign]*weight*foreign
          reg price trunk gr
          scalar b_trunk = _b[trunk]
          scalar b_gr = _b[gr]
          scalar b_cons = _b[_cons]
          
          bootstrap t_trunk=r(t_trunk) t_gr=r(t_gr) t_cons=r(t_cons), reps(100) seed(12345) saving(bs_t, replace): myprog
          preserve
          use bs_t, replace
          centile t_trunk, centile(2.5, 97.5)
          centile t_gr, centile(2.5, 97.5)
          centile t_cons, centile(2.5, 97.5)
          gen t_abs_trunk = abs(t_trunk)
          gen t_abs_gr = abs(t_gr)
          gen t_abs_cons = abs(t_cons)
          centile t_abs_trun t_abs_gr t_abs_cons, centile(95)
          restore
          Thanks George,

          With my limited coding abilities I think it will take me a day or two to understand this. I'm grateful that you spent so much time to help me out.



          Comment


          • #20
            I ripped the general setup from
            HTML Code:
            https://www.schmidheiny.name/teaching/bootstrap2up.pdf
            This bootstraps the critical t-stats for each variable in the second stage equation (since the nominal ones are presumed incorrect). You'd compare the t-stats from the regression to these values rather than the normal table. First set is asymmetric values, the second is a symmetric. I think the former is probably better, but others may disagree.

            You can fancy it up where it makes a nice table if that's your desire.

            The main thing is that both equations are part of the bootstrap procedure (each round generates a new generated regressor gr).

            Comment


            • #21
              Gagandeep:
              another source to grasp the building blocks ogf George's helpful advice, is Example 3, -bootstrap- entry, Stata .pdf manual.
              Kind regards,
              Carlo
              (Stata 19.0)

              Comment


              • #22
                Originally posted by George Ford View Post
                Code:
                sysuse auto, clear
                reg price mpg weight length foreign
                * use this if you want the prediction of the regression
                predict pfit , xb
                * use this if you want parts of the regression (2 ways to get to the same result)
                gen newvar = _b[_cons] + _b[mpg]*mpg + _b[weight]*weight +_b[length]*length
                gen newvaralt = pfit-_b[foreign]*foreign
                * newvar = newvaralt
                You've got ugly variable names. If you have trouble matching up the variable names with the coefficients (_b[x]), then

                Code:
                matrix list e(b)
                to see what Stata sees.




                Hi George,

                Terribly sorry to bother you again. if possible can you address my original query. I have tried multiple iterations but I keep getting results which aren't theoretically possible.

                Post the regression command:

                regress actual_tier1_gap l.tier1_gap1 l.((c.tier1_gap1)#(i.state1nonstate0 c.size c.return_on_equity_w ///
                c.provforNPA_to_net_advances_w i.Listeddummy1iflisted c.GdpGrowthRate c.inflation)), noconst

                I need to construct a new variable VarX = ΛhatZi,t-1 where vector Z is (i.state1nonstate0 c.size c.return_on_equity_w i.below_tier1 c.provforNPA_to_net_advances_w i.Listeddummy1iflisted c.GdpGrowthRate c.inflation)
                since in the regression all these variables are interacted with Gapi,t-1 so to get the original coefficient in vector z is following approach correct?

                generate X = ((_b[cL.tier1_gap1#cL.size] / (_b[L.tier1_gap1])) * L.size) --------- (for one of the variables in vector z, and so on adding all the variables)

                in short, is the true Λhat in vector Zi,t-1 given by: [_b(l.variable*l.gap)/_b(l.gap)] for each variable in the vector Z?
                Last edited by gagandeep sharma; 10 Nov 2021, 16:35.

                Comment


                • #23
                  Use all the variables you want to include in generate X to get a single X.

                  Comment


                  • #24
                    Originally posted by George Ford View Post
                    Use all the variables you want to include in generate X to get a single X.
                    Thanks George,

                    Could you please comment on this:

                    Since in the regression individual Betas are the product of two variables (variable*gap), is the true Λhat in vector Zi,t-1 given by: [_b(l.variable*l.gap)/_b(l.gap)] for each variable in the vector Z?

                    so that i can use:

                    generate X = ((_b[cL.tier1_gap1#cL.size] / (_b[L.tier1_gap1])) * L.size) --------- (for one of the variables in vector z, and so on adding all the variables)

                    Comment


                    • #25
                      I don't think you need to include a ratio, but I'm not sure exactly what you're after. You have a linear model with a lot of interactions. Not sure where the ratio comes into play if you want a prediction from that regression. If the theory calls for it, then sure.

                      Comment

                      Working...
                      X