Announcement

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

  • Constraints does not work in gsem

    Hello,

    I want to add constraints to a gsem model. I have multiply imputed data and I want to first pool results across the multiply imputed datasets, and then re-run the model for each imputed dataset, constraining the model parameters to be equal to the pooled results. In case of interest, I am doing this to get an overall Likelihood Ratio test statistic (see here).

    For some reason, so far, Stata only adds some specified constraints to the model but not others. Does anyone know why please? Code with some annotation below.

    Code:
    // Missing Data from: https://stats.idre.ucla.edu/stata/seminars/mi_in_stata_pt1_new/
    use https://stats.idre.ucla.edu/wp-content/uploads/2017/05/hsb2_mar.dta, clear
    mi set flong
    mi register imputed female write read math prog science
    mi impute chained ///
        (logit) female (mlogit) prog (regress) write read math science = socst, ///
        add(10) rseed (53421)
    
    // Overall model
    mi estimate, cmdok post: gsem (write <- i.ses read) (ses <- read, mlogit), ///
        group(female) ginvariant(none)
    
    // Loops through estimated parameters and makes them into constraints.
    matrix b=e(b)
    local vars: colfullnames b
    constraint drop _all
    foreach var of local vars{
        local i=`i'+1
        constraint `i' _b[`var'] = `=_b[`var']'
    }
    constraint dir
    
    // Re-runs model with constraints added.
    mi unset, asis
    numlist "1(1)9"
    gsem (write <- i.ses read) (ses <- read, mlogit), ///
        group(female) ginvariant(none) constraints(`r(numlist)') if _mi_m==1
    // Some but not all constraints successful applied
    Thanks,

    Liam




Working...
X