Announcement

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

  • GLM and Margins to obtain mean costs

    Hi everyone,

    I am analysing a data with the aim to generate mean cost for two treatment arms A and B. I have 2 variables: type (Before or After) and age. Treatment A has 104 patients and B has 116 patients.

    To do this, I used the following command:

    bysort treatment: glm totalcost i.type i.age

    This gave me exactly what I was looking for i.e. effect of type and age on total cost according to treatment A and treatment B.

    To get the mean cost, I used the margins command.

    margins type

    This gave me the following table:

    Predictive margins
    Model VCE: OIM

    Expression: Predicted mean total, predict () Number of obs = 116
    Type Margin SE z P|z| [95% Conf. Interval]
    Before 41758.05 5360.599 7.79 0.000 31251.47 52264.63
    After 64857.69 7530.048 8.61 0.000 50099.06 79616.31
    I noticed that 'margins type' gave me the mean costs for both the types but only for treatment B, as shown by the number of observations.

    So, I was wondering if you can help me figure out the reason behind this and how to obtain a similar table for treatment A?
    Last edited by Dikshyanta Rana; 20 Jun 2019, 08:09.

  • #2
    Dear Dikshyanta:
    what you experienced can be explained considering that -margins- is fed by the second -glm- estimate only (ie, B, in your case).
    To avoid this you should type:
    Code:
    glm totalcost i.type i.age if treatment=="A"
    margins
    glm totalcost i.type i.age if treatment=="B"
    margins
    As an aside, I suspect that a -glm- with -family(gamma)- and -link(log)- would be better for your data.
    Kind regards,
    Carlo
    (Stata 18.0 SE)

    Comment


    • #3
      Hi Carlo,

      Thank you so much. You're absolutely right! It does provide a better fit. I forgot to add family and log while writing the question above.

      Have a nice day!

      Kind regards,
      Dikshyanta



      Comment

      Working...
      X