Announcement

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

  • Function like SAS: Proc syslin

    Hello everyone,

    I would like to ask whether Stata has the function like SAS syslin command,

    Here is what I trying to do. my model: y= x1+x2+x1*x2, and I would like to test whether x1+x1*x2 >0.

    In Sas I could run as below:

    Proc syslin data =one;
    Model y = x1 x2 x1*x2;
    test x1 + x1*x2 ne 0;
    run;

    Is there anyway we can do in Stata?

    Thanks in advance

  • #2
    I'm not familiar with RPOC SYSLIN, but this looks to be estimating a linear model (y=x1 + x2 + x1*x2) and then performing a hypothesis test about a linear combination of coefficients for x1 and x2. If this is what you want, then something like the following will work.

    Since I didn't see a CLASS statement in your SAS code, I assume that x1 and x2 are both continuous. If they are are not, then this code needs to be changed slightly.

    Code:
    reg y c.x1##c.x2
    lincom _b[x1] + _b[x1#x2]
    This will test the linear combination of x1 + x1*x2 against the null hypothesis of zero.

    You may find it helpful to read the help for -help lincom-, -help test- and -help factor variables-.

    Comment


    • #3
      Originally posted by Leonardo Guizzetti View Post
      I'm not familiar with RPOC SYSLIN, but this looks to be estimating a linear model (y=x1 + x2 + x1*x2) and then performing a hypothesis test about a linear combination of coefficients for x1 and x2. If this is what you want, then something like the following will work.

      Since I didn't see a CLASS statement in your SAS code, I assume that x1 and x2 are both continuous. If they are are not, then this code needs to be changed slightly.

      Code:
      reg y c.x1##c.x2
      lincom _b[x1] + _b[x1#x2]
      This will test the linear combination of x1 + x1*x2 against the null hypothesis of zero.

      You may find it helpful to read the help for -help lincom-, -help test- and -help factor variables-.
      Hi Leonardo,

      Thanks for your reply.

      I want to test if the coefficients x1 + x1*x2 > 0. and here both x1 and x2 are dummy variables. in that case, should I change the code?

      Comment


      • #4
        In that case, you could show us a data example. If x1 and x2 only have two levels, and are coded as 0/1, then this would work:

        Code:
        reg y i.x1##i.x2
        lincom _b[1.x1] + _b[1.x1#1.x2]
        Lincom and -test- both give two-sided Wald-type tests, so you can modify the output in the usual way if you really do want a one-sided test. (Note that testing != 0 implies a two-sided test in your initial post.) For example, see this FAQ.

        Comment


        • #5
          Originally posted by Leonardo Guizzetti View Post
          In that case, you could show us a data example. If x1 and x2 only have two levels, and are coded as 0/1, then this would work:

          Code:
          reg y i.x1##i.x2
          lincom _b[1.x1] + _b[1.x1#1.x2]
          Lincom and -test- both give two-sided Wald-type tests, so you can modify the output in the usual way if you really do want a one-sided test. (Note that testing != 0 implies a two-sided test in your initial post.) For example, see this FAQ.
          Thank you Leonardo, I will check the FAQ, and thanks for your code and time
          .

          Comment


          • #6
            Originally posted by Leonardo Guizzetti View Post
            In that case, you could show us a data example. If x1 and x2 only have two levels, and are coded as 0/1, then this would work:

            Code:
            reg y i.x1##i.x2
            lincom _b[1.x1] + _b[1.x1#1.x2]
            Lincom and -test- both give two-sided Wald-type tests, so you can modify the output in the usual way if you really do want a one-sided test. (Note that testing != 0 implies a two-sided test in your initial post.) For example, see this FAQ.
            Hi Leonardo,

            I try to use lincom and test, is there anyway that I could directly do a one-side test? the code I used showed as below:

            Code:
            reg y x1 x2 x1*x2
            test _b[1.x1]+_b[1.x1#1.x2]=0
            local signbeta=sign(_b[1.x1]+_b[1.x1#1.x2])
            display "Ho: coef >= 0  p-value = " 1-ttail(r(df_r),`signbeta'*sqrt(r(F)))
            display "Ho: coef <= 0  p-value = " ttail(r(df_r),`signbeta'*sqrt(r(F)))
            Somehow I am not sure where went wrong the the p value I got for coef>=0 and coef<=0 are exactly the same. Mind if you could tell me where I did wrong?

            Comment


            • #7
              Sorry, it seems the output of -test- and -lincom- are little different, but still usable with some tweaking. -test- outputs an F-test with 1 numerator degree of freedom and k denomintor degrees of freedom, whereas -lincom- gives a t-test with k degrees of freedom.

              As an example, let's start with a dataset that you can follow along with on your own copy of Stata. I'm setting up an interaction between two indicator variables, each coded as 0 or 1.

              Code:
              sysuse auto
              recode rep78 (1/3=0) (4/5=1) , gen(repair)
              
              reg price i.foreign##i.repair
              To use -test- as in the FAQ, you can do this:

              [/code]
              . test _b[1.foreign] + _b[1.foreign#1.repair] = 0

              ( 1) 1.foreign + 1.foreign#1.repair = 0

              F( 1, 65) = 0.38
              Prob > F = 0.5373

              . local sign_combo = sign(_b[1.foreign] + _b[1.foreign#1.repair])
              . display "Ho: coef >= 0 p-value = " 1 - ttail(r(df_r),`sign_combo'*sqrt(r(F)))

              Ho: coef >= 0 p-value = .73134831
              [/code]

              To use -lincom-, some slight adjustments are needed to account for the lincom. We use the t-statistic instead of the F-statistic, and we can dispense with the sign, since that is included with the t-statistic.

              Code:
              . lincom _b[1.foreign] + _b[1.foreign#1.repair]
              
               ( 1)  1.foreign + 1.foreign#1.repair = 0
              
              ------------------------------------------------------------------------------
                     price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
              -------------+----------------------------------------------------------------
                       (1) |   700.4192   1129.369     0.62   0.537    -1555.086    2955.924
              ------------------------------------------------------------------------------
              
              . display "Ho: coef >=  p-value = " 1 - ttail(r(df), r(t))
              Ho: coef >=  p-value = .73134831

              Comment


              • #8
                Originally posted by Leonardo Guizzetti View Post
                Sorry, it seems the output of -test- and -lincom- are little different, but still usable with some tweaking. -test- outputs an F-test with 1 numerator degree of freedom and k denomintor degrees of freedom, whereas -lincom- gives a t-test with k degrees of freedom.

                As an example, let's start with a dataset that you can follow along with on your own copy of Stata. I'm setting up an interaction between two indicator variables, each coded as 0 or 1.

                Code:
                sysuse auto
                recode rep78 (1/3=0) (4/5=1) , gen(repair)
                
                reg price i.foreign##i.repair
                To use -test- as in the FAQ, you can do this:

                [/code]
                . test _b[1.foreign] + _b[1.foreign#1.repair] = 0

                ( 1) 1.foreign + 1.foreign#1.repair = 0

                F( 1, 65) = 0.38
                Prob > F = 0.5373

                . local sign_combo = sign(_b[1.foreign] + _b[1.foreign#1.repair])
                . display "Ho: coef >= 0 p-value = " 1 - ttail(r(df_r),`sign_combo'*sqrt(r(F)))

                Ho: coef >= 0 p-value = .73134831
                [/code]

                To use -lincom-, some slight adjustments are needed to account for the lincom. We use the t-statistic instead of the F-statistic, and we can dispense with the sign, since that is included with the t-statistic.

                Code:
                . lincom _b[1.foreign] + _b[1.foreign#1.repair]
                
                ( 1) 1.foreign + 1.foreign#1.repair = 0
                
                ------------------------------------------------------------------------------
                price | Coef. Std. Err. t P>|t| [95% Conf. Interval]
                -------------+----------------------------------------------------------------
                (1) | 700.4192 1129.369 0.62 0.537 -1555.086 2955.924
                ------------------------------------------------------------------------------
                
                . display "Ho: coef >= p-value = " 1 - ttail(r(df), r(t))
                Ho: coef >= p-value = .73134831
                Hi Leonardo,

                Thank you so much for this, this works fine. I am very grateful for your help.

                Very best regards,

                Lucas

                Comment

                Working...
                X