Announcement

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

  • Combine Regression Coefficients

    Hello,

    I am using lincom in StataSE 15 to compute standard errors, t-stat, p-values and confidence intervals for linear combinations of coefficients derived from regress. Rather than inputting the lincom command for each combination, I would like to run a single command for all the combinations of coefficients I want and output as one table, is this possible or do I have to use a different command.

    Example,
    regress deg4 age score exper female
    lincom _b[_cons] + _b[age]
    lincom _b[_cons] + _b[score]
    lincom _b[_cons] + _b[exper]
    lincom _b[_cons] + _b[female]
    Deg4 Coef. Std. Err. t P>|t| [95% Conf. Interval]
    (1) .2301388 .0197375 11.66 0.000 .1914445 .2688331
    (2)
    (3)
    (4)
    Thank you,

  • #2
    Unfortunately this is not possible with lincom as it does not support multiple expressions.

    You can, however, use nlcom, which is intended for non-linear combinations but can be used for linear combinations as well.
    Code:
    nlcom (_b[_cons] + _b[age]) ///
          (_b[_cons] + _b[score]) ///
          (_b[_cons] + _b[exper]) ///
          (_b[_cons] + _b[female])

    Comment


    • #3
      Thanks Wouter Wakker but it doesn't work. It treats as a single combination
      Click image for larger version

Name:	output.png
Views:	1
Size:	6.1 KB
ID:	1549846

      Comment


      • #4
        You don't show us the nlcom command you ran, so we have to guess at what you did wrong. The following example works as expected.
        Code:
        . sysuse auto, clear
        (1978 Automobile Data)
        
        . quietly regress price weight length
        
        . nlcom (_b[_cons] + _b[weight]) ///
        >       (_b[_cons] + _b[length])
        
               _nl_1:  _b[_cons] + _b[weight]
               _nl_2:  _b[_cons] + _b[length]
        
        ------------------------------------------------------------------------------
               price |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
               _nl_1 |   10391.24    4309.09     2.41   0.016     1945.578     18836.9
               _nl_2 |   10288.58   4270.377     2.41   0.016     1918.794    18658.37
        ------------------------------------------------------------------------------

        Comment


        • #5
          William Lisowski, I don't know what I'm doing wrong. I used your sample data and got a different error
          Click image for larger version

Name:	output1.png
Views:	1
Size:	14.1 KB
ID:	1549863

          Comment


          • #6
            You're probably running the code from the command window. This doesn't work if your code has multiple lines connected by '///'. Make sure you're running the code from a do-file or remove the forward slashes and put everything on a single line.
            Last edited by Wouter Wakker; 28 Apr 2020, 12:49.

            Comment


            • #7
              Thank you. It works perfectly.

              Comment

              Working...
              X