Announcement

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

  • xtregar with constraints

    Dear All,

    suppose that I have the dependent var. Y and several regressors X_1, X_2, X_3, X_4.

    I want to run a fixed effect reg. with the constraint (beta_1 + beta_2 + beta_3 =1)and AR(1) error.

    Now I know that xtregar can construct an FE model with an AR(1) disturbance, but it cannot directly combine with constraints or include X_1 in a model with the coefficient constrained to 1, like using the offset() option.

    I wonder if I can substitute X_2 and X_3 with X_2_new (X_2 - X_1) and X_3_new (X_3 - X_1) and directly divide X_1 in both side and run regression like, Y/X_1 - 1 = beta_0 + X_2_new/X_1 + X_3_new/X_1 +X_4/X_1 ? will this work?

    Or if you have any ideas about how can I achieve my target by using other commands?

    Any help would be much appreciated.

    Best,
    Ivy

  • #2
    Maybe something along these lines.

    Code:
    webuse grunfeld , clear
    xtset company time
    
    capture program drop doreg
    program define doreg
        version 14.0
        
        quietly {
        
        syntax varlist [if], Panelvar(varname) Timevar(varname) [rho(real 0)]
        tokenize `varlist'
        local y `1'
        local x1 `2'
        local x2 `3'
        
        xtset `panelvar' `timevar'
        
        * GET RHO
        if `rho' == 0 {
            xtregar `y' `x1' `x2' , fe 
            local rho = e(rho_ar)
        }
        
        * DEMEAN BY PANEL
        foreach var of varlist `y' `x1' `x2' {
            by `panelvar': egen mean_`var' = mean(`var')
            gen dm_`var' = `var' - mean_`var'
        }
        
        * AR(1) TRANSFORMATION 
        foreach var of varlist dm_* {
            gen ar_`var' = `var' - `rho' * l.`var'
        }
        
        ** ESTIMATE XTREGAR UNCONSTRAINED
        eststo e1: xtregar `y' `x1' `x2', fe rhotype(dw)
        
        ** ESTIMATE NEW VARIABLES UNCONSTRAINED FOR COMPARISON
        eststo e2: reg ar_dm_`y' ar_dm_`x1' ar_dm_`x2'  
        
        * ESTIMATE CONSTRAINED REGRESSION
        constraint define 1 _b[ar_dm_`x1'] + _b[ar_dm_`x2']  = 1
        eststo e3: cnsreg ar_dm_`y' ar_dm_`x1' ar_dm_`x2', constraints(1)
        
        } //quietly end
        
        esttab e1 e2 e3 , mtitle(xtregar compare constrained)
        di "rho = " %5.3f `rho'
        
        * CLEAN UP
        foreach var of varlist `y' `x1' `x2'  {
            drop mean_`var' dm_`var'  ar_dm_`var'
        }
    end
    
    doreg invest mvalue kstock, panelvar(company) timevar(time)

    Comment


    • #3
      This works. Not sure all the options needed, but it works.

      Code:
      webuse grunfeld , clear
      xtset company time
      
      constraint define 1 mvalue + kstock = 1
      
      xtgls invest mvalue kstock , corr(ar1)  
      linest, c(1)
      
      xtgls invest mvalue kstock , p(c) corr(ar1)
      linest, c(1)

      Comment


      • #4
        That works!!! Thanks for your help George!

        Comment

        Working...
        X