Announcement

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

  • New on SSC: mlincom - multiple linear combinations of parameters

    Thanks to Kit Baum, a new package mlincom is now available from SSC.

    mlincom (multiple lincom) computes point estimates, standard errors, t or z statistics, p-values, and confidence intervals for multiple linear combinations of coefficients as well as their covariances. nlcom is also able to do this, but mlincom is much faster (up to 300 times for complex models). mlincom internally calls lincom for each linear combination and extracts estimates and variances from its output. It has an optional post option to post estimation results for subsequent testing or exporting with pretty table commands.

    I would like to thank Roger Newson, his command lincomest has been useful for me in developing this command, and a small part of the code is now also part of mlincom in adapted form.

    Examples from help mlincom:
    Code:
    . // Setup
    . webuse regress
    
    . regress y x1 x2 x3
    
          Source |       SS           df       MS      Number of obs   =       148
    -------------+----------------------------------   F(3, 144)       =     96.12
           Model |   3259.3561         3  1086.45203   Prob > F        =    0.0000
        Residual |  1627.56282       144  11.3025196   R-squared       =    0.6670
    -------------+----------------------------------   Adj R-squared   =    0.6600
           Total |  4886.91892       147  33.2443464   Root MSE        =    3.3619
    
    ------------------------------------------------------------------------------
               y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
              x1 |   1.457113    1.07461     1.36   0.177     -.666934    3.581161
              x2 |   2.221682   .8610358     2.58   0.011     .5197797    3.923583
              x3 |   -.006139   .0005543   -11.08   0.000    -.0072345   -.0050435
           _cons |   36.10135   4.382693     8.24   0.000     27.43863    44.76407
    ------------------------------------------------------------------------------
    
    . 
    . // Estimate linear combinations of coefficients with lincom
    . lincom x2-x1
    
     ( 1)  - x1 + x2 = 0
    
    ------------------------------------------------------------------------------
               y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             (1) |   .7645682   .9950282     0.77   0.444     -1.20218    2.731316
    ------------------------------------------------------------------------------
    
    . lincom 3*x1 + 500*x3
    
     ( 1)  3*x1 + 500*x3 = 0
    
    ------------------------------------------------------------------------------
               y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             (1) |   1.301825   3.396624     0.38   0.702    -5.411858    8.015507
    ------------------------------------------------------------------------------
    
    . lincom 3*x1 + 500*x3 - 12
    
     ( 1)  3*x1 + 500*x3 = 12
    
    ------------------------------------------------------------------------------
               y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             (1) |  -10.69818   3.396624    -3.15   0.002    -17.41186   -3.984493
    ------------------------------------------------------------------------------
    
    . 
    . // Estimate linear combinations of coefficients with mlincom
    . mlincom (x2-x1) (3*x1 + 500*x3) (3*x1 + 500*x3 - 12)
    
            lc_1:  x2-x1 = 0
            lc_2:  3*x1 + 500*x3 = 0
            lc_3:  3*x1 + 500*x3 - 12 = 0
    
    ------------------------------------------------------------------------------
               y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
            lc_1 |   .7645682   .9950282     0.77   0.444     -1.20218    2.731316
            lc_2 |   1.301825   3.396624     0.38   0.702    -5.411858    8.015507
            lc_3 |  -10.69818   3.396624    -3.15   0.002    -17.41186   -3.984493
    ------------------------------------------------------------------------------
    
    . 
    . // Estimate linear combinations of coefficients with mlincom, label transformations
    . mlincom ((name1) x2-x1) ((name2) 3*x1 + 500*x3) ((name3) 3*x1 + 500*x3 - 12)
    
           name1:  x2-x1 = 0
           name2:  3*x1 + 500*x3 = 0
           name3:  3*x1 + 500*x3 - 12 = 0
    
    ------------------------------------------------------------------------------
               y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
           name1 |   .7645682   .9950282     0.77   0.444     -1.20218    2.731316
           name2 |   1.301825   3.396624     0.38   0.702    -5.411858    8.015507
           name3 |  -10.69818   3.396624    -3.15   0.002    -17.41186   -3.984493
    ------------------------------------------------------------------------------
    
    . 
    . // Estimate linear combinations of coefficients with mlincom, label transformations and post results
    . mlincom ((name1) x2-x1) ((name2) 3*x1 + 500*x3) ((name3) 3*x1 + 500*x3 - 12), post
    
           name1:  x2-x1 = 0
           name2:  3*x1 + 500*x3 = 0
           name3:  3*x1 + 500*x3 - 12 = 0
    
    ------------------------------------------------------------------------------
               y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
           name1 |   .7645682   .9950282     0.77   0.444     -1.20218    2.731316
           name2 |   1.301825   3.396624     0.38   0.702    -5.411858    8.015507
           name3 |  -10.69818   3.396624    -3.15   0.002    -17.41186   -3.984493
    ------------------------------------------------------------------------------
    
    . 
    end of do-file

  • #2
    I got some comments from people pointing out that there already exists a command named mlincom, which is part of the spost13 package. This is problematic for people who want to use both, so I decided to rename (my) mlincom, which is now available as xlincom from SSC thanks to Kit Baum.
    Code:
    ado uninstall mlincom
    ssc install xlincom

    Comment


    • #3
      Thanks to Kit Baum, an update for xlincom is available from SSC.

      xlincom now offers all options that lincom does (apart from undocumented options), and supports the same syntax as lincom in most cases (and in all cases for single linear combinations).

      What xlincom does that lincom doesn't:
      • post results
      • calculate multiple combinations simultaneously
      • calculate covariances in case of multiple combinations
      • label transformations

      Comment


      • #4
        Thanks to Kit Baum another update is available from SSC.

        xlincom now has a repost option which adds the estimated linear combinations to the estimates in memory. This makes it easy to include include linear combinations together with model estimates in a formatted table. I kindly thank Ben Jann for suggesting this approach to me, which led to the repost option.

        Here is an example using esttab (from SSC).

        Code:
        . webuse gxmpl1
        
        . reg gnp L(0/2).cpi
        
              Source |       SS           df       MS      Number of obs   =         6
        -------------+----------------------------------   F(3, 2)         =   6332.77
               Model |  2681355.03         3   893785.01   Prob > F        =    0.0002
            Residual |  282.273149         2  141.136575   R-squared       =    0.9999
        -------------+----------------------------------   Adj R-squared   =    0.9997
               Total |   2681637.3         5  536327.461   Root MSE        =     11.88
        
        ------------------------------------------------------------------------------
                 gnp |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
                 cpi |
                 --. |   145.9597   13.98614    10.44   0.009     85.78222    206.1373
                 L1. |  -32.43789   25.39491    -1.28   0.330    -141.7034     76.8276
                 L2. |  -14.69746   12.58422    -1.17   0.363      -68.843    39.44807
                     |
               _cons |  -7448.648    228.593   -32.58   0.001    -8432.204   -6465.092
        ------------------------------------------------------------------------------
        
        . xlincom (t = cpi) (t1 = cpi + l1.cpi) (t2 = cpi + l1.cpi + l2.cpi), repost
        
                   t:  cpi = 0
                  t1:  cpi + l1.cpi = 0
                  t2:  cpi + l1.cpi + l2.cpi = 0
        
        ------------------------------------------------------------------------------
                 gnp |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
        main         |
                 cpi |
                 --. |   145.9597   13.98614    10.44   0.009     85.78222    206.1373
                 L1. |  -32.43789   25.39491    -1.28   0.330    -141.7034     76.8276
                 L2. |  -14.69746   12.58422    -1.17   0.363      -68.843    39.44807
                     |
               _cons |  -7448.648    228.593   -32.58   0.001    -8432.204   -6465.092
        -------------+----------------------------------------------------------------
        xlincom      |
                   t |   145.9597   13.98614    10.44   0.009     85.78222    206.1373
                  t1 |   113.5219   13.77212     8.24   0.014     54.26522    172.7785
                  t2 |    98.8244   1.398928    70.64   0.000      92.8053    104.8435
        ------------------------------------------------------------------------------
        
        . esttab, eqlabels("Main" "Sum of coefficients", span)
        
        ----------------------------
                              (1)   
                              gnp   
        ----------------------------
        Main                        
        cpi                 146.0** 
                          (10.44)   
        
        L.cpi              -32.44   
                          (-1.28)   
        
        L2.cpi             -14.70   
                          (-1.17)   
        
        _cons             -7448.6***
                         (-32.58)   
        ----------------------------
        Sum of coefficients         
        t                   146.0** 
                          (10.44)   
        
        t1                  113.5*  
                           (8.24)   
        
        t2                  98.82***
                          (70.64)   
        ----------------------------
        N                       6   
        ----------------------------
        t statistics in parentheses
        * p<0.05, ** p<0.01, *** p<0.001

        Comment


        • #5
          Hi,
          I just discovered the command xlincom. Nevertheless, I have some problems with the option repost. This gives me an error:
          option resize not allowed
          r(198);

          end of do-file

          r(198);

          This does not happen when I just use the option post.

          Code:
          xtreg netmig_rate c.temp_MA3_decadal_change c.temp_MA3_decadal_change#(1.rural_pop 1.middle_rural_pop 1.middle_urban_pop) ///
          c.pop_growth_rate#(1.rural_pop 1.middle_rural_pop 1.middle_urban_pop 1.urban_pop) i.ccode ///
          c.precip_MA3_decadal_change#(1.rural_pop 1.middle_rural_pop 1.middle_urban_pop 1.urban_pop) ///
           i.year#(1.rural_pop 1.middle_rural_pop 1.middle_urban_pop 1.urban_pop) if Q_GDPpc_world==1, fe cluster(grid_id)
          xlincom  (t1 = c.temp_MA3_decadal_change + c.temp_MA3_decadal_change#1.rural_pop), repost
          
                    t1:  c.temp_MA3_decadal_change + c.temp_MA3_decadal_change#1.rural_pop = 0
          And after that I get the error.

          I hope someone can help me. Thanks!

          Comment


          • #6
            Michael Schuster Thank you for your interest in xlincom and for reporting this problem.

            To add the estimated linear combinations to the estimates in memory, the repost option relies on ereturn repost, which ony works after estimation commands that use ereturn post to post their results. This is also documented in the help file. xtreg with the fe option is not one of them.

            Fortunately, I already had coded a workaround for regress, which doesn't post results with ereturn post either but relies on _regress to do this. xtreg, fe calls _regress as well to estimate and post results, so I could use the same workaround.

            The updated version which supports the repost option after xtreg,fe is available from GitHub:
            Code:
            ado uninstall xlincom
            net install xlincom, from(https://raw.githubusercontent.com/WWakker/xlincom/master/)
            It will also be available from SSC soon.


            Comment


            • #7
              Wouter Wakker Thank you so much for your reply and the command in general! This is very helpful! It perfectly works now. While I'm at it and you still seem to be working on the scc, I wanted to ask if it is possible to use the command in combination with -est store-, since it does not work yet? Or do I sth wrong:

              Code:
              xtreg netmig_rate c.tempdc c.pop_growth_rate#(1.rural_pop i.middle_rural_pop 1.middle_urban_pop 1.urban_pop) ///
               i.ccode if Q_GDPpc_world==1, fe vce(cluster grid_id)
              est store pa1
               
              xtreg netmig_rate c.tempdc tempdc_mu tempdc_mr tempdc_r ///
              c.pop_growth_rate#(1.rural_pop 1.middle_rural_pop 1.middle_urban_pop 1.urban_pop) i.ccode ///
              c.precip_MA3_decadal_change#(1.rural_pop 1.middle_rural_pop 1.middle_urban_pop 1.urban_pop) ///
              i.year#(1.rural_pop 1.middle_rural_pop 1.middle_urban_pop 1.urban_pop) if Q_GDPpc_world==1, fe cluster(grid_id)
              xlincom (t = c.tempdc + tempdc_mu), repost
              est store pa2
              
              *********************************************************************
              esttab pa1 pa2 using "table_1_Baseline_Naive_results.tex", replace ///
              star(* 0.10 ** 0.05 *** 0.01) noconstant interaction("$\times$") r2 ///
              $scalar_2 ///
              nonotes noomitted noobs label ///
              mtitles("" "" ) se  ///
              collabels("",lhs(Dep. var.: Net migration rate))
              *********************************************************************
              Thanks for the great work!


              Comment


              • #8
                Michael Schuster It's important to realise that your model pa1 is a single equation model, while your second model is stored as a multiple equation model, with equations "main" and "xlincom". esttab needs to know how to join these equations, so probably you need to specify the option equations(1) to match the first equations from both models.
                Last edited by Wouter Wakker; 12 Nov 2020, 13:34.

                Comment


                • #9
                  @Wouter Wakker. I try to run your example codes,but get an error.My Stata version is 17.0 SE.Can you help to solve this problem?
                  Code:
                         webuse gxmpl1
                           reg gnp L(0/2).cpi
                           xlincom (t = cpi) (t1 = cpi + l1.cpi) (t2 = cpi + l1.cpi + l2.cpi),repost
                          r(9999);
                          end of do-file
                          r(9999);
                  Best regards.

                  Raymond Zhang
                  Stata 17.0,MP

                  Comment


                  • #10
                    Raymond Zhang Thanks for reporting this issue. I can replicate the problem on my work laptop (Stata MP 16.0) but not on my personal laptop (Stata 15.1 SE). I couldn't find a cause of this error, and the only thing I know is that error 9999 is a system error. I thought I might be able to work around this by setting the version to 15, but this doesn't help neither.

                    9xxx. Various messages, all indicating an unexpected system failure. You should never see such a message. If one occurs,
                    save your data, and exit Stata immediately. Please email [email protected] to report the problem.
                    I contacted Stata tech support and will let you know once I know more.

                    Comment


                    • #11
                      Originally posted by Wouter Wakker View Post
                      Raymond Zhang Thanks for reporting this issue. I can replicate the problem on my work laptop (Stata MP 16.0) but not on my personal laptop (Stata 15.1 SE). I couldn't find a cause of this error, and the only thing I know is that error 9999 is a system error. I thought I might be able to work around this by setting the version to 15, but this doesn't help neither.



                      I contacted Stata tech support and will let you know once I know more.
                      Thank you for your reply.I find that if I have 2 linear combinations of coefficients,then it will run well.But if there are more than 2 combinations of coefficients, it will get an error.
                      Code:
                      webuse gxmpl1,clear
                      reg gnp L(0/2).cpi
                      xlincom (t1 = cpi + l1.cpi) (t2 = cpi + l1.cpi + l2.cpi),repost
                      
                      
                                t1:  cpi + l1.cpi = 0
                                t2:  cpi + l1.cpi + l2.cpi = 0
                      
                      ------------------------------------------------------------------------------
                               gnp | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
                      -------------+----------------------------------------------------------------
                      Main         |
                               cpi |
                               --. |   145.9597    13.9861    10.44   0.009      85.7822    206.1373
                               L1. |   -32.4379    25.3949    -1.28   0.330    -141.7034     76.8276
                               L2. |   -14.6975    12.5842    -1.17   0.363     -68.8430     39.4481
                                   |
                             _cons |  -7.45e+03   228.5930   -32.58   0.001    -8.43e+03   -6.47e+03
                      -------------+----------------------------------------------------------------
                      xlincom      |
                                t1 |   113.5219    13.7721     8.24   0.014      54.2652    172.7785
                                t2 |    98.8244     1.3989    70.64   0.000      92.8053    104.8435
                      ------------------------------------------------------------------------------
                      
                      . 
                      end of do-file
                      
                      
                      xlincom (t3=cpi) (t4 = cpi + l1.cpi) (t4 = cpi + l1.cpi + l2.cpi),repost
                      
                                t3:  cpi = 0
                                t4:  cpi + l1.cpi = 0
                                t4:  cpi + l1.cpi + l2.cpi = 0
                      r(9999);
                      
                      end of do-file
                      
                      r(9999);
                      Best regards.

                      Raymond Zhang
                      Stata 17.0,MP

                      Comment


                      • #12
                        Raymond Zhang Tech support just got back to me. They found that this problem is related to a bug introduced in Stata 16. They have added it to their bug database and will fix it soon, although they cannot give an exact date.

                        Unfortunately it won't be possible to use the full capabilities of xlincom until then, but I'd be happy to provide a manual workaround using nlcom if you give me a bit more info on what you're trying to do exactly.

                        Comment

                        Working...
                        X