Announcement

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

  • Simulate a multilevel ordinal logistic regression in stata

    Dear All,

    Please could anyone help to simulate a multilevel ordinal logistic regression?

    Here is an example of what I would like:
    Code:
    clear
    webuse pig
    mixed weight week || id: week
    xtile weight_cate = weight, nq(5) 
    meologit weight_cate  week || id: week, difficult
    I would like to simulate data from the model performed "meologit weight_cate week || id: week". Basically, I would like to generate simulated data using specified estimates from the meologit.


    Many thanks

    Andre



  • #2
    You can do something like the following with a user-written command, -grologit-, to convert the linear predictor into an ordered-categorical outcome variable. See below for a typical use case.

    .ÿ
    .ÿversionÿ17.0

    .ÿ
    .ÿclearÿ*

    .ÿ
    .ÿsetÿseedÿ`=strreverse("1610200")'

    .ÿ
    .ÿquietlyÿdrawnormÿinterceptÿslope,ÿdoubleÿsd(3ÿ2)ÿcorr(1ÿ-0.5ÿ\ÿ-0.5ÿ1)ÿn(300)

    .ÿgenerateÿintÿpidÿ=ÿ_n

    .ÿ
    .ÿquietlyÿexpandÿ10

    .ÿbysortÿpid:ÿgenerateÿbyteÿtimÿ=ÿ_n

    .ÿ
    .ÿgenerateÿdoubleÿxbuÿ=ÿ0ÿ+ÿ0ÿ*ÿtimÿ+ÿinterceptÿ+ÿ(timÿ-ÿ5.5)ÿ/ÿ4.5ÿ*ÿslope

    .ÿ
    .ÿlocalÿcut_list

    .ÿforvaluesÿthresholdÿ=ÿ1/4ÿ{
    ÿÿ2.ÿÿÿÿÿlocalÿcutÿ=ÿlogit(`threshold'ÿ/ÿ5)
    ÿÿ3.ÿÿÿÿÿlocalÿcut_listÿ`cut_list'ÿ`cut'
    ÿÿ4.ÿ}

    .ÿgrologitÿxbu,ÿgenerate(sco)ÿcuts(`cut_list')

    .ÿ
    .ÿgenerateÿdoubleÿctiÿ=ÿ(timÿ-ÿ5.5)ÿ/ÿ4.5

    .ÿmeologitÿscoÿc.ctiÿ||ÿpid:ÿcti,ÿcovariance(unstructured)ÿnolog

    Mixed-effectsÿologitÿregressionÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿNumberÿofÿobsÿÿÿÿÿ=ÿÿÿÿÿÿ3,000
    Groupÿvariable:ÿpidÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿNumberÿofÿgroupsÿÿ=ÿÿÿÿÿÿÿÿ300

    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿObsÿperÿgroup:
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿminÿ=ÿÿÿÿÿÿÿÿÿ10
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿavgÿ=ÿÿÿÿÿÿÿ10.0
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿmaxÿ=ÿÿÿÿÿÿÿÿÿ10

    Integrationÿmethod:ÿmvaghermiteÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿIntegrationÿpts.ÿÿ=ÿÿÿÿÿÿÿÿÿÿ7

    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿWaldÿchi2(1)ÿÿÿÿÿÿ=ÿÿÿÿÿÿÿ0.24
    Logÿlikelihoodÿ=ÿ-3295.9724ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿProbÿ>ÿchi2ÿÿÿÿÿÿÿ=ÿÿÿÿÿ0.6233
    --------------------------------------------------------------------------------
    ÿÿÿÿÿÿÿÿÿÿÿscoÿ|ÿCoefficientÿÿStd.ÿerr.ÿÿÿÿÿÿzÿÿÿÿP>|z|ÿÿÿÿÿ[95%ÿconf.ÿinterval]
    ---------------+----------------------------------------------------------------
    ÿÿÿÿÿÿÿÿÿÿÿctiÿ|ÿÿÿ.0700144ÿÿÿÿ.142537ÿÿÿÿÿ0.49ÿÿÿ0.623ÿÿÿÿ-.2093531ÿÿÿÿ.3493818
    ---------------+----------------------------------------------------------------
    ÿÿÿÿÿÿÿÿÿ/cut1ÿ|ÿÿ-1.113663ÿÿÿ.1882026ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ-1.482533ÿÿÿ-.7447928
    ÿÿÿÿÿÿÿÿÿ/cut2ÿ|ÿÿ-.1185266ÿÿÿ.1872892ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ-.4856067ÿÿÿÿ.2485534
    ÿÿÿÿÿÿÿÿÿ/cut3ÿ|ÿÿÿ.7086144ÿÿÿ.1879387ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ.3402613ÿÿÿÿ1.076968
    ÿÿÿÿÿÿÿÿÿ/cut4ÿ|ÿÿÿ1.615364ÿÿÿ.1901522ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ1.242672ÿÿÿÿ1.988055
    ---------------+----------------------------------------------------------------
    pidÿÿÿÿÿÿÿÿÿÿÿÿ|
    ÿÿÿÿÿÿÿvar(cti)|ÿÿÿ4.036835ÿÿÿ.5842765ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ3.039774ÿÿÿÿ5.360938
    ÿÿÿÿÿvar(_cons)|ÿÿÿ9.473944ÿÿÿ1.080381ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ7.576388ÿÿÿÿ11.84675
    ---------------+----------------------------------------------------------------
    pidÿÿÿÿÿÿÿÿÿÿÿÿ|
    ÿcov(cti,_cons)|ÿÿ-2.425427ÿÿÿ.6641623ÿÿÿÿ-3.65ÿÿÿ0.000ÿÿÿÿ-3.727161ÿÿÿ-1.123693
    --------------------------------------------------------------------------------
    LRÿtestÿvs.ÿologitÿmodel:ÿchi2(3)ÿ=ÿ1871.17ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿProbÿ>ÿchi2ÿ=ÿ0.0000

    Note:ÿLRÿtestÿisÿconservativeÿandÿprovidedÿonlyÿforÿreference.

    .ÿestatÿsd
    ---------------------------------------------------------------------------------
    ÿÿÿÿÿÿÿÿÿÿÿÿscoÿ|ÿCoefficientÿÿStd.ÿerr.ÿÿÿÿÿÿzÿÿÿÿP>|z|ÿÿÿÿÿ[95%ÿconf.ÿinterval]
    ----------------+----------------------------------------------------------------
    pidÿÿÿÿÿÿÿÿÿÿÿÿÿ|
    ÿÿÿÿÿÿÿÿÿsd(cti)|ÿÿÿ2.009188ÿÿÿ.1454012ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ1.743495ÿÿÿÿÿ2.31537
    ÿÿÿÿÿÿÿsd(_cons)|ÿÿÿ3.077977ÿÿÿ.1755018ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ2.752524ÿÿÿÿ3.441911
    ÿcorr(cti,_cons)|ÿÿ-.3921952ÿÿÿ.0867803ÿÿÿÿ-4.52ÿÿÿ0.000ÿÿÿÿ-.5479142ÿÿÿ-.2102066
    ---------------------------------------------------------------------------------

    .ÿ
    .ÿexit

    endÿofÿdo-file


    .


    I've attached the command's ado-file if you want to use that (no warranty), or you can scan through it in order to see what it does if you feel like writing something analogous yourself. There's no help file, but you first generate the linear predictions and feed those to it, along with a -numlist- of thresholds (cuts), and name of the ordered-categorical outcome variable to be generated. The default is parameterization is logit, but you can specify probit as an option.
    Attached Files

    Comment


    • #3
      Dear Joseph Coveney,


      Many thanks for your help.


      I don't think I was clear in my last email. I don't want to simulate data using a linear predictor. This is because I would not know which values to include there.

      What I want to do is to start with a meologit model such as the one below and then simulate data assuming similar estimates

      Click image for larger version

Name:	p.png
Views:	1
Size:	24.3 KB
ID:	1610337



      I know nothing about the linear predictor. I'm sorry if I'm not understanding something


      I know how to simulate data from a linear mixed model but I do not know how to do it from a ordinal mixed model. I would like to do a similar thing for the meologit to the following that used a continuous outcome:

      Code:
      clear
      webuse pig
      mixed weight week || id: week, stddev
      
      clear
      set obs 48
      gen id = _n
      
      generate u_0i = rnormal(0,2.599301)
      generate u_1i = rnormal(0,.6066851)
      
      expand 9
      bysort id: generate week = _n
      
      generate e_ij = rnormal(0,1.264441)
      
      generate weight = 19.35561 + 6.209896*week + u_0i + week*u_1i + e_ij
      
      mixed weight week || id: week, stddev


      Many thanks in advance for your help

      Andrew
      Last edited by Andrew Xavier; 18 May 2021, 05:25.

      Comment


      • #4
        Originally posted by Andrew Xavier View Post
        What I want to do is to start with a meologit model such as the one below and then simulate data assuming similar estimates
        I basically showed you how in my illustration above. But, here: let's go through an example step-by-step. I'll use the dataset from the helpfile for -meologit-. Each step is identified by a comment in the illustration below.

        .ÿ
        .ÿversionÿ17.0

        .ÿ
        .ÿclearÿ*

        .ÿ
        .ÿsetÿseedÿ`=strreverse("1610200")'

        .ÿ
        .ÿ//ÿOriginalÿdataÿandÿmodel
        .ÿquietlyÿwebuseÿtvsfpors

        .ÿmeologitÿthkÿc.prethkÿ||ÿschool:ÿprethk,ÿcovariance(unstructured)ÿnolog

        Mixed-effectsÿologitÿregressionÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿNumberÿofÿobsÿÿÿÿÿ=ÿÿÿÿÿÿ1,600
        Groupÿvariable:ÿschoolÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿNumberÿofÿgroupsÿÿ=ÿÿÿÿÿÿÿÿÿ28

        ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿObsÿperÿgroup:
        ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿminÿ=ÿÿÿÿÿÿÿÿÿ18
        ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿavgÿ=ÿÿÿÿÿÿÿ57.1
        ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿmaxÿ=ÿÿÿÿÿÿÿÿ137

        Integrationÿmethod:ÿmvaghermiteÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿIntegrationÿpts.ÿÿ=ÿÿÿÿÿÿÿÿÿÿ7

        ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿWaldÿchi2(1)ÿÿÿÿÿÿ=ÿÿÿÿÿÿ71.47
        Logÿlikelihoodÿ=ÿ-2128.0901ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿProbÿ>ÿchi2ÿÿÿÿÿÿÿ=ÿÿÿÿÿ0.0000
        -----------------------------------------------------------------------------------
        ÿÿÿÿÿÿÿÿÿÿÿÿÿÿthkÿ|ÿCoefficientÿÿStd.ÿerr.ÿÿÿÿÿÿzÿÿÿÿP>|z|ÿÿÿÿÿ[95%ÿconf.ÿinterval]
        ------------------+----------------------------------------------------------------
        ÿÿÿÿÿÿÿÿÿÿÿprethkÿ|ÿÿÿ.3859692ÿÿÿ.0456554ÿÿÿÿÿ8.45ÿÿÿ0.000ÿÿÿÿÿ.2964862ÿÿÿÿ.4754521
        ------------------+----------------------------------------------------------------
        ÿÿÿÿÿÿÿÿÿÿÿÿ/cut1ÿ|ÿÿ-.5981441ÿÿÿ.1323143ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ-.8574753ÿÿÿ-.3388129
        ÿÿÿÿÿÿÿÿÿÿÿÿ/cut2ÿ|ÿÿÿ.6459577ÿÿÿ.1312459ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ.3887205ÿÿÿÿ.9031948
        ÿÿÿÿÿÿÿÿÿÿÿÿ/cut3ÿ|ÿÿÿ1.830222ÿÿÿ.1383338ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ1.559093ÿÿÿÿ2.101351
        ------------------+----------------------------------------------------------------
        schoolÿÿÿÿÿÿÿÿÿÿÿÿ|
        ÿÿÿÿÿÿÿvar(prethk)|ÿÿÿ.0138004ÿÿÿ.0149784ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ.0016445ÿÿÿÿ.1158108
        ÿÿÿÿÿÿÿÿvar(_cons)|ÿÿÿ.2137879ÿÿÿ.1248098ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ.0680848ÿÿÿÿ.6712994
        ------------------+----------------------------------------------------------------
        schoolÿÿÿÿÿÿÿÿÿÿÿÿ|
        ÿcov(prethk,_cons)|ÿÿ-.0138234ÿÿÿ.0356992ÿÿÿÿ-0.39ÿÿÿ0.699ÿÿÿÿ-.0837925ÿÿÿÿ.0561457
        -----------------------------------------------------------------------------------
        LRÿtestÿvs.ÿologitÿmodel:ÿchi2(3)ÿ=ÿ54.36ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿProbÿ>ÿchi2ÿ=ÿ0.0000

        Note:ÿLRÿtestÿisÿconservativeÿandÿprovidedÿonlyÿforÿreference.

        .ÿ
        .ÿ//ÿRetrieveÿcorrelationÿmatrixÿofÿrandomÿeffects
        .ÿestatÿsd
        ------------------------------------------------------------------------------------
        ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿthkÿ|ÿCoefficientÿÿStd.ÿerr.ÿÿÿÿÿÿzÿÿÿÿP>|z|ÿÿÿÿÿ[95%ÿconf.ÿinterval]
        -------------------+----------------------------------------------------------------
        schoolÿÿÿÿÿÿÿÿÿÿÿÿÿ|
        ÿÿÿÿÿÿÿÿÿsd(prethk)|ÿÿÿ.1174751ÿÿÿ.0637512ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ.0405524ÿÿÿÿ.3403098
        ÿÿÿÿÿÿÿÿÿÿsd(_cons)|ÿÿÿÿ.462372ÿÿÿ.1349668ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ.2609306ÿÿÿÿ.8193286
        ÿcorr(prethk,_cons)|ÿÿ-.2544938ÿÿÿ.5085934ÿÿÿÿ-0.50ÿÿÿ0.617ÿÿÿÿ-.8682853ÿÿÿÿ.6671809
        ------------------------------------------------------------------------------------

        .ÿtempnameÿSDsÿCorr

        .ÿmatrixÿdefineÿ`SDs'ÿ=ÿr(b)[1,ÿ6],ÿr(b)[1,ÿ5]

        .ÿmatrixÿdefineÿ`Corr'ÿ=ÿr(b)[1,ÿ7]

        .ÿmatrixÿdefineÿ`Corr'ÿ=ÿ(1,ÿ`Corr'ÿ\ÿ`Corr',ÿ1)

        .ÿ
        .ÿ//ÿRetrieveÿthresholdsÿinÿaÿnumlist
        .ÿlocalÿcut_listÿ`=_b[/cut1]'ÿ`=_b[/cut2]'ÿ`=_b[/cut3]'

        .ÿ
        .ÿ//ÿRetrieveÿfixedÿeffectsÿregressionÿcoefficient
        .ÿtempnameÿprethk

        .ÿscalarÿdefineÿ`prethk'ÿ=ÿ_b[prethk]

        .ÿ
        .ÿ*
        .ÿ*ÿBeginÿhere
        .ÿ*
        .ÿ//ÿGenerateÿrandomÿeffects
        .ÿquietlyÿdrawnormÿinterceptÿslope,ÿdoubleÿsd(`SDs')ÿcorr(`Corr')ÿn(300)ÿclear

        .ÿgenerateÿintÿschoolÿ=ÿ_n

        .ÿ
        .ÿ//ÿGenerateÿfixedÿeffects
        .ÿquietlyÿexpandÿ60

        .ÿgenerateÿbyteÿprethkÿ=ÿruniformint(0,ÿ6)

        .ÿ
        .ÿ//ÿAssembleÿlinearÿpredictions
        .ÿgenerateÿdoubleÿxbuÿ=ÿ0ÿ+ÿ`prethk'ÿ*ÿprethkÿ+ÿinterceptÿ+ÿprethkÿ*ÿslope

        .ÿ
        .ÿ//ÿDrawÿorderedÿcategoricalÿoutcomeÿvariableÿfromÿlinearÿpredictorÿvariable
        .ÿgrologitÿxbu,ÿgenerate(thk)ÿcut(`cut_list')

        .ÿ
        .ÿ//ÿFitÿsameÿmodelÿtoÿrandomlyÿgeneratedÿdataset
        .ÿmeologitÿthkÿc.prethkÿ||ÿschool:ÿprethk,ÿcovariance(unstructured)ÿnolog

        Mixed-effectsÿologitÿregressionÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿNumberÿofÿobsÿÿÿÿÿ=ÿÿÿÿÿ18,000
        Groupÿvariable:ÿschoolÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿNumberÿofÿgroupsÿÿ=ÿÿÿÿÿÿÿÿ300

        ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿObsÿperÿgroup:
        ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿminÿ=ÿÿÿÿÿÿÿÿÿ60
        ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿavgÿ=ÿÿÿÿÿÿÿ60.0
        ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿmaxÿ=ÿÿÿÿÿÿÿÿÿ60

        Integrationÿmethod:ÿmvaghermiteÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿIntegrationÿpts.ÿÿ=ÿÿÿÿÿÿÿÿÿÿ7

        ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿWaldÿchi2(1)ÿÿÿÿÿÿ=ÿÿÿÿ1250.44
        Logÿlikelihoodÿ=ÿ-17743.669ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿProbÿ>ÿchi2ÿÿÿÿÿÿÿ=ÿÿÿÿÿ0.0000
        -----------------------------------------------------------------------------------
        ÿÿÿÿÿÿÿÿÿÿÿÿÿÿthkÿ|ÿCoefficientÿÿStd.ÿerr.ÿÿÿÿÿÿzÿÿÿÿP>|z|ÿÿÿÿÿ[95%ÿconf.ÿinterval]
        ------------------+----------------------------------------------------------------
        ÿÿÿÿÿÿÿÿÿÿÿprethkÿ|ÿÿÿ.3886831ÿÿÿ.0109917ÿÿÿÿ35.36ÿÿÿ0.000ÿÿÿÿÿ.3671398ÿÿÿÿ.4102263
        ------------------+----------------------------------------------------------------
        ÿÿÿÿÿÿÿÿÿÿÿÿ/cut1ÿ|ÿÿ-1.787299ÿÿÿ.0442344ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ-1.873997ÿÿÿ-1.700601
        ÿÿÿÿÿÿÿÿÿÿÿÿ/cut2ÿ|ÿÿ-.6130374ÿÿÿ.0388468ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ-.6891757ÿÿÿ-.5368991
        ÿÿÿÿÿÿÿÿÿÿÿÿ/cut3ÿ|ÿÿÿ.6316631ÿÿÿ.0385692ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ.5560689ÿÿÿÿ.7072573
        ------------------+----------------------------------------------------------------
        schoolÿÿÿÿÿÿÿÿÿÿÿÿ|
        ÿÿÿÿÿÿÿvar(prethk)|ÿÿÿ.0132339ÿÿÿ.0028087ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ.0087304ÿÿÿÿ.0200605
        ÿÿÿÿÿÿÿÿvar(_cons)|ÿÿÿ.2150665ÿÿÿ.0348413ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ.1565582ÿÿÿÿ.2954402
        ------------------+----------------------------------------------------------------
        schoolÿÿÿÿÿÿÿÿÿÿÿÿ|
        ÿcov(prethk,_cons)|ÿÿ-.0123389ÿÿÿÿ.007877ÿÿÿÿ-1.57ÿÿÿ0.117ÿÿÿÿ-.0277776ÿÿÿÿ.0030997
        -----------------------------------------------------------------------------------
        LRÿtestÿvs.ÿologitÿmodel:ÿchi2(3)ÿ=ÿ554.68ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿProbÿ>ÿchi2ÿ=ÿ0.0000

        Note:ÿLRÿtestÿisÿconservativeÿandÿprovidedÿonlyÿforÿreference.

        .ÿ
        .ÿexit

        endÿofÿdo-file


        .

        Comment


        • #5
          Many thanks for your help on this. Your example is very clear.

          Could I ask you one more question:

          Let's say I have a dataset and I want to simulate a variable that is correlated/associated by a specific amount with a categorical and continuous variable in that dataset. Let's say that the variable I want to simulate is either categorical or continuous

          How do I do that?

          Again thanks in advance for your help.

          ​​​​​​​Andrew

          Comment


          • #6
            You're not clear to me, I'm sorry.

            I'm assuming that you mean ordered categorical when you say categorical, and that you mean Pearson correlation coefficient when you say "correlated/associated . . . by a specific amount".

            But I can't tell what you mean by a variable that is "either categorical or continuous", and by another that is "a categorical and continuous variable in the dataset".

            In general, you can fit mixed-response regression models with the user-written command -gllamm- (SSC) and with -gsem- (official Stata), and represent association between two or more outcome variables by a latent factor (random effect). You can simulate using -drawnorm- with correlation matrix to yield the desired latent factor variance in a manner directly analogous to the two illustrations above. You can also simulate as if for a conventional random effect and then discretize one or more observations per cluster. You might need to hone in on the desired variance in a trial-and-error manner.
            Last edited by Joseph Coveney; 21 May 2021, 04:28.

            Comment


            • #7
              Sorry if I was not clear in my last email. My other question was a lot simpler

              Lets say I have the following

              webuse tvsfpors, clear

              in the dataset there is the continuous variable prethk and categorical ordinal variable thk

              The dataset is clustered

              What i would like to do is the following:
              - generate a continuous variable (x) that is associated prethk with a correlation of 0.75
              - generate a categorical ordinal variable with 4 categories (y) that is associated with prethk in terms of a specific linear increase
              - generate a continuous variable (w) that is associated with thk in terms of s specific increase in the odds
              - is there a way to generate a categorical ordinal variable (A) that is both associated with prethk and thk so I could have a model such as this: meologit thk c.prethk i.A || school: prethk, covariance(unstructured)
              - Is there a way to generate a continuous variable (B) that is both associated with weight (continuous) and week (continuous) so I could have a model such as this: mixed weight c.week c.B || id: week

              Basically, I would like to simulate variables that are both associated with other predictors and response in multilevel models (linear and ordinal models) using existing data and existing variables

              I suppose this may involve simulating some form of interaction but I don't know exactly how to do it...

              I hope this makes sense

              Many Thanks

              A
              Last edited by Andrew Xavier; 21 May 2021, 06:43.

              Comment


              • #8
                Originally posted by Andrew Xavier View Post
                Basically, I would like to simulate variables that are both associated with other predictors and response in multilevel models (linear and ordinal models) using existing data and existing variables

                I suppose this may involve simulating some form of interaction but I don't know exactly how to do it...
                You would do it using the same general method illustrated above, that is, emulating the data-generating process that you are modeling and using estimates from the earlier fitted model for the parameter values. It wouldn't involve an interaction term unless you posit an interaction of the predictors.

                Comment


                • #9
                  Many thanks for your advice. You helped me to solve my problem, BW, A

                  Comment

                  Working...
                  X