Announcement

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

  • xtsur - limit to usefulness Any ideas?

    Dear List,

    I am running two xtreg (re) models, separately for males and females, with the same LHS & RHS variables. I want to test equality of coefficients across models Male & Females with the same LHS & RHS variables. xtsur has restrictions which I can't get around [user written xtsur from http://fmwww.bc.edu/RePEc/bocode/x; Minh Cong Nguyen & Hoa Bao Nguyen dated 2009]. Using the authors example data and based on their examples I do the following and get these Stata's error. (I think I have tried every combination without success.)

    Does anyone have experience with this and know of a work-around?

    Thanks
    Laurence

    Code:
    use xtsur_example.dta, clear 
    ** This is the data that comes with xtdur help , but is called "example.dta"
    
    * Two ifs are not allowed (only one that restricts both equations (see below)
    global eqn1 (y1 x1 x2 x3) if PanelID<72
    global eqn2 (y2 x4 x6 x7) if PanelID>71
    xtsur $eqn1 $eqn2
       Error: invalid '(' 
    
    * Try constructing 2 variables as RHS 
    gen Z1=y1 if PanelID<72
    gen Z2=y1 if PanelID>71
    global eqn1 (Z1 x1 x2 x3)
    global eqn2 (Z2 x1 x2 x3)
    xtsur $eqn1 $eqn2
    (running multi-step estimates...)
    Error: no observations
    
    xtsur (Z1 Z2 = x1 x2 x3 x4 x6 x7 x9), onestep
    Error: no observations
    
    xtsur (equname1: y1 x2 x3 x4 if PanelID<72 ) (equname2: y1 x2 x3 x4)
    Error: if not allowed
    
    xtsur (equname1: y1 x2 x3 x4) (equname2: y1 x1 x3 x4) if PanelID<72
    Ok, but not what I want

  • #2
    Originally posted by Laurence Lester View Post
    . . . I want to test equality of coefficients across models Male & Females with the same LHS & RHS variables.
    Not familiar with the\at user-written command, but from its blurb on SSC, it seems to be intended more for fitting models with different outcome (LHS) variables within the same observation, which is not what you want.

    For your objective, I suggest something more along the following lines. (Begin at the "Begin here" comment; the stuff above it is for creating the toy dataset for illustration.)
    Code:
    ersion 18.0
    
    clear *
    
    // seedem
    set seed 341404363
    
    quietly set obs 150
    generate `c(obs_t)' pid = _n
    generate double pid_u = rnormal()
    generate byte sex = mod(_n, 2)
    
    generate double pre = runiform(-0.5, 0.5)
    
    quietly expand 10
    bysort pid: generate byte tim = _n
    
    generate double out = rnormal(pid_u)
    
    *
    * Begin here
    *
    mixed out i.sex##c.pre i.sex##i.tim || pid: , residuals(independent, by(sex)) ///
        mle nolrtest nolog
    
    /* "test equality of coefficients across models Male & Females with the same
        LHS & RHS variables" */
    testparm 1.sex // <= test of sex-related difference in the constant (intercept)
    testparm 1.sex#i.tim
    testparm 1.sex#c.pre
    
    exit
    I've included separate residual error terms in the model in case the potential for heteroscedasticity concerns you, but it's optional.

    Comment


    • #3
      reg y1 x2 x3 x4 c.male#(c.x2 c.x3 c.x4)

      the x2/x3/x4 coefficients are for female, and the interactions tells you the difference between females and males (sum them for the male coefficients).

      or

      reg i.sex#(c.x2 c.x3 c.x4)

      which gives you the coefficients for each gender and then you can test the difference using test/lincom etc..



      Comment


      • #4
        or run the second model for the coefficients, and use the first for a test of equality.

        Comment


        • #5
          you should include the gender/male variable as a standalone regressor too.

          Comment


          • #6
            Code:
            sysuse auto, clear
            
            reg price weight displacement foreign c.foreign#(c.weight c.displacement)
            reg price foreign i.foreign#(c.weight c.displacement)
            lincom 0.foreign#c.weight - 1.foreign#c.weight 
            lincom 0.foreign#c.displacement - 1.foreign#c.displacement

            Comment


            • #7
              Thank you George and Joseph. (I have replicated Joseph's process and am now working on George's, but using xtreg)

              Comment


              • #8
                xtsur isn't going to get you anything over regression in this case. it is more limited (no clustering, e.g.,) and having the same X's produces OLS results.

                Comment


                • #9
                  Thanks. Considering this may be a very interesting question in may cases I'm somewhat surprise that the multitude of econometricians who are far more advance than me have not come up with a solution ( I think I have have searched the web as far as is practical).

                  My latest attempt is to run two models and then use "ttest" like this:

                  Code:
                  xtreg LnIncome_Hourly_Real i.Education if sex==1 & wave<6.  vce(cluster ID)
                  xtreg LnIncome_Hourly_Real i.Education if sex==1 & wave>17, vce(cluster ID)
                  ** 2.Education in first model =  0.1468842  
                  test _b[2.Education]=0.1469 // hard code M1
                  (I appreciate this does not include data, but I don't think it is necessary in this case.)
                  Can any experts tell my why this is not theoretically legitimate.

                  Thanks
                  Laurence

                  Comment


                  • #10
                    Originally posted by Laurence Lester View Post
                    . . . I'm somewhat surprise that the multitude of econometricians who are far more advance than me have not come up with a solution
                    I'm guessing that the multitude already has come up with a solution, viz.,
                    Code:
                    generate byte tim = cond(wave < 6, 0, cond(wave > 17, 1, .))
                    xtreg LnIncome_Hourly_Real i.Education##i.tim if sex == 1
                    test 2.Education#1.tim
                    
                    // or
                    
                    replace tim = cond(wave < 6, 0, cond(wave > 17, 1, 2))
                    xtreg LnIncome_Hourly_Real i.Education##i.tim if sex == 1 & inlist(tim, 0, 1)
                    test 2.Education#1.tim

                    Comment


                    • #11
                      #9 is incorrect.

                      You are testing whether the coefficient is equal to a value, when you want to test whether two coefficients, both with distributions, are equal.

                      I assume you want the RE estimator, since xtreg is defaulting to it. xtsur is likewise RE.

                      #10 is a proper setup.

                      There is no reason to estimate two models. You are making it harder than it needs to be.

                      Comment

                      Working...
                      X