Announcement

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

  • Can mcp command be used to compute marginal effects for continuous variable after fitting a xtmelogit model in Stata?

    The dataset is here:
    insheet using "https://stats.idre.ucla.edu/stat/data/hdp.csv", comma
    foreach i of varlist familyhx smokinghx sex cancerstage school {
    encode `i', gen(`i'2)
    drop `i'
    rename `i'2 `i'
    }

    xtmelogit remission il6 crp i.cancerstage lengthofstay c.pain c.pain#i.cancerstage|| did: , intpoints(10)

    To this step, everything seems Ok.

    However, when I used the Stata code below, the error messages prompted

    mcp pain cancerstage

    There was a problem executing -margins-.

    The command issued was essentially as follows: margins , at( pain=( 1 2 3 4 5 6 7 8 9) cancerstage=( 1 2 3 4)) r(498);

    Does anybody know if mcp command is not allowed to be used after fitting a xtemologit model?

    Thank you!
    Last edited by smith Jason; 01 Jun 2022, 09:41.

  • #2
    Anybody here can help me? Thank you!

    Comment


    • #3
      anybody?

      Comment


      • #4
        feel depressed ….,

        Comment


        • #5
          I am sorry I cannot answer for mcp or mcp2, but does
          Code:
          margins cancerstage, at(pain=(1(1)9)) plot
          do what you want?

          Comment


          • #6
            Thank you for your response! If the model now is
            xtmelogit remission il6 crp i.cancerstage lengthofstay c.pain#i.cancerstage c.pain c.pain#c.pain c.pain#c.pain#i.cancerstage|| did: , intpoints(10)

            How can I use margins to compute it?
            Last edited by smith Jason; 02 Jun 2022, 15:08.

            Comment


            • #7
              Originally posted by smith Jason View Post
              If the model now is
              xtmelogit remission il6 crp i.cancerstage lengthofstay c.pain#i.cancerstage c.pain c.pain#c.pain c.pain#c.pain#i.cancerstage|| did: , intpoints(10)

              How can I use margins to compute it?
              It would be the same as Eddy showed. Adding the quadratic term, so long as you use factor variable notation to do it, wouldn't change the margins statement, because margins is designed to work seamlessly with factor variable notation.

              Try this and see for yourself.
              Code:
              version 17.0
              
              clear *
              
              import delimited using "https://stats.idre.ucla.edu/stat/data/hdp.csv", ///
                  varnames(1) asdouble
              
              label define CancerStages 1 I 2 II 3 III 4 IV
              encode cancerstage, generate(stage) label(CancerStages) noextend
              drop cancerstage
              rename stage cancerstage
              
              melogit remission c.(il6 crp lengthofstay) c.pain##c.pain##i.cancerstage || did: , nolog
              
              margins cancerstage, at(pain = (1 5 9)) // <= Here
              
              marginsplot , xdimension(cancerstage) plotdimension(pain) ///
                  noci title("") ///
                  ytitle(Remission Rate) ylabel( , format(%02.1f) angle(horizontal) nogrid) ///
                  legend(position(7) ring(0))
              
              exit

              Comment


              • #8
                Thank you!

                Comment


                • #9
                  Thank you!For the same variable, If I want to plot the marginal effects of M-SD,M, and M+SD, How can I do it? By the way, c_pain is the centered variable and it replaced the c.pain in the model for ease of interpretation.

                  Comment


                  • #10

                    This is the plot I graphed with mcp2 command.
                    Attached Files
                    Last edited by smith Jason; 03 Jun 2022, 08:03.

                    Comment

                    Working...
                    X