Announcement

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

  • twopm with weights

    Hi there,

    I'd like to run a two part model as follows but can't seem to get the weights to work. The use of poisson distribution for the GLM model was based on the modified park's test.

    Any advice much appreciated.

    twopm tothealthcarecost i.ace_cat_b i.GENDER i.age_cat i.educ i.K1 i.F2 i.region i.ETHNICITY if sample == 1 & missing_ace == 0 [aweight=weighttrim], firstpart(logit) secondpart(glm, family(poisson) link(log)) vce(robust)


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(tothealthcarecost ace_cat_b) byte GENDER float(age_cat educ) byte(K1 F2) float region byte ETHNICITY float(sample missing_ace weighttrim)
          0 0 2 4 0 3 6 0 3 1 0   5.377788
    1900000 0 2 1 1 5 4 1 2 1 0  .02180295
          0 0 1 1 1 1 4 1 1 1 0 .011189446
    2374000 0 1 3 1 4 4 1 1 1 0 .021811957
     450000 0 1 1 0 5 2 1 1 1 0   .7457822
          0 0 2 4 1 1 7 1 2 1 0   .0649344
          0 0 1 3 0 1 4 1 1 1 0  1.4537774
    2950000 0 2 1 1 5 5 1 1 1 0  .02180295
          0 0 2 2 0 1 7 0 5 1 0   5.775696
          0 0 1 4 1 1 7 1 4 1 0 .033324864
    1450000 0 2 1 1 5 4 0 5 1 0  .05074032
          0 0 1 3 1 1 7 1 1 1 0 .021811957
    1600000 0 1 3 0 1 4 1 1 1 0  1.4537774
          0 0 1 1 0 1 6 1 1 1 0   .7457822
          0 0 1 4 1 1 5 1 1 1 0 .033324864
          0 0 2 1 1 5 2 0 3 0 0          .
          0 0 2 1 0 5 6 0 2 1 0   3.381867
    1900000 0 2 4 1 4 4 1 1 1 0   .0649344
          0 0 2 3 0 1 5 1 1 1 0   2.832725
          0 0 2 2 1 1 7 1 2 1 0  .05413437
          0 0 2 4 1 4 5 1 5 1 0   .0649344
          0 0 1 2 0 1 4 1 2 1 0  1.8516984
     450000 0 1 3 1 1 7 0 3 1 0  .05076127
     474000 0 2 2 1 1 6 1 1 1 0  .05413437
          0 0 2 4 1 1 1 1 4 1 0   .0649344
     750000 0 1 1 1 5 4 0 4 1 0  .02604031
    1450000 0 1 1 0 5 1 0 1 1 0   1.735601
     308000 0 1 1 1 1 1 1 2 1 0 .011189446
     150000 0 2 1 1 5 4 1 1 1 0  .02180295
     450000 0 2 2 1 1 1 1 1 1 0  .05413437
          0 0 2 3 1 1 7 0 4 1 0  .09890965
          0 0 2 3 1 1 4 1 2 1 0  .04250114
          0 0 2 2 1 1 7 1 1 1 0  .05413437
    2074000 0 2 2 1 1 7 1 1 1 0  .05413437
          0 0 1 3 0 1 4 1 1 1 0  1.4537774
          0 0 2 3 1 1 7 0 4 1 0  .09890965
          0 0 1 3 1 5 5 0 5 1 0  .05076127
          0 0 1 1 1 5 2 1 1 1 0 .011189446
          0 0 1 3 1 1 7 1 5 1 0 .021811957
     150000 0 2 2 1 5 7 1 5 1 0  .05413437
          0 0 1 2 1 1 6 1 1 1 0  .02778219
          0 0 1 2 0 1 3 1 1 0 0          .
          0 0 2 2 1 1 7 1 1 1 0  .05413437
          0 0 2 4 1 4 7 1 5 1 0   .0649344
          0 0 1 4 1 1 5 1 1 1 0 .033324864
          0 0 1 2 0 1 6 1 1 1 0  1.8516984
    1450000 0 1 1 1 1 6 1 1 1 0 .011189446
          0 0 1 1 1 1 7 1 1 1 0 .011189446
          0 0 1 2 1 1 7 1 5 1 0  .02778219
          0 0 2 3 0 1 1 1 5 1 0   2.832725
          0 0 1 4 1 1 7 1 5 1 0 .033324864
          0 0 1 1 1 5 5 0 5 1 0  .02604031
          0 0 2 3 0 1 4 1 5 1 0   2.832725
          0 0 2 4 1 3 7 1 2 1 0   .0649344
    1450000 0 1 1 0 5 4 1 2 0 0          .
          0 0 1 1 0 5 2 1 1 1 0   .7457822
          0 0 2 2 1 1 1 1 1 1 0  .05413437
     158000 0 2 2 1 5 7 1 5 1 0  .05413437
          0 0 1 1 0 1 4 1 1 1 0   .7457822
     450000 0 2 1 1 5 7 1 1 1 0  .02180295
          0 0 1 2 1 1 7 1 1 1 0  .02778219
    3950000 0 2 1 1 5 3 0 5 1 0  .05074032
          0 0 2 3 0 1 4 0 4 1 0   5.564115
     150000 0 1 1 1 5 3 0 1 1 0  .02604031
          0 0 1 1 1 5 4 1 2 1 0 .011189446
          0 0 2 2 0 1 7 1 1 1 0   3.608084
    1450000 0 2 3 0 1 5 1 1 1 0   2.832725
    3350000 0 2 1 0 1 6 1 1 1 0   1.453177
          0 0 1 3 0 1 4 1 1 1 0  1.4537774
          0 0 1 3 1 1 7 1 1 1 0 .021811957
          0 0 2 2 0 1 5 1 1 1 0   3.608084
          0 0 1 1 0 1 2 0 3 1 0   1.735601
    1900000 0 2 1 1 5 2 1 1 1 0  .02180295
     150000 0 2 2 1 1 7 1 1 1 0  .05413437
    3950000 0 1 4 0 1 5 0 4 1 0   5.169037
          0 0 1 2 0 3 3 1 1 1 0  1.8516984
    4124000 0 2 2 1 1 7 1 2 1 0  .05413437
          0 0 2 1 0 1 5 1 2 1 0   1.453177
          0 0 1 2 1 5 3 0 5 1 0  .06465532
          0 0 1 2 0 1 6 1 1 1 0  1.8516984
          0 0 1 1 0 5 4 1 1 1 0   .7457822
     316000 0 1 1 1 1 6 1 2 1 0 .011189446
          0 0 1 2 0 1 4 0 5 1 0   4.309315
          0 0 1 2 0 1 6 1 2 1 0  1.8516984
          0 0 2 3 1 1 7 0 4 1 0  .09890965
     900000 0 2 1 1 1 6 1 2 1 0  .02180295
          0 0 1 3 1 1 7 1 2 1 0 .021811957
     450000 0 2 2 1 1 7 1 1 1 0  .05413437
          0 0 1 4 1 3 7 1 1 1 0 .033324864
          0 0 2 1 1 1 2 0 5 1 0  .05074032
     450000 0 1 2 0 5 1 1 1 1 0  1.8516984
          0 0 1 1 1 1 7 1 2 1 0 .011189446
          0 0 2 5 1 5 5 1 5 1 0   5.353928
          0 0 2 3 0 1 4 1 2 1 0   2.832725
          0 0 1 2 0 1 4 1 1 1 0  1.8516984
          0 0 1 1 1 1 1 0 3 1 0  .02604031
     158000 0 2 2 1 1 7 1 1 1 0  .05413437
          0 0 1 3 1 1 5 1 1 1 0 .021811957
    2240000 0 2 3 1 1 1 1 1 1 0  .04250114
     450000 0 1 1 0 1 4 1 1 1 0   .7457822
    end

    Many thanks
    Karen

  • #2
    All I can say on this is that your model implies one part that uses logistic regression (logit) and -logit- does not support -aweight-s. You will need to consider a more appropriate choice of weights here.

    Comment


    • #3
      Also, you are trying to estimate a count model in the 2nd part. Note that the help for twopm says

      twopm is designed to estimate models in which the positive outcome is continuous. It does not deal with discrete or count outcomes.
      I think the help file is a little confusing, because it lists all the standard glm options, but only a few work correctly with twopm. Further, there is no error trapping when you do use an illegitimate option.

      You may be lucky you got the aweights error, because otherwise you might not have realized the twopm command doesn't do what you want it to.
      -------------------------------------------
      Richard Williams
      Professor Emeritus of Sociology
      University of Notre Dame
      StataNow Version: 19.5 MP (2 processor)

      EMAIL: [email protected]
      WWW: https://academicweb.nd.edu/~rwilliam/

      Comment


      • #4
        Are you sure you need a count model though? Would plain old regress be ok? twopm also has examples like this:

        Two-part model with probit and linear regression of log(depvar>0)
        . twopm wage educ age married children, firstpart(probit) secondpart(regress, log)
        -------------------------------------------
        Richard Williams
        Professor Emeritus of Sociology
        University of Notre Dame
        StataNow Version: 19.5 MP (2 processor)

        EMAIL: [email protected]
        WWW: https://academicweb.nd.edu/~rwilliam/

        Comment


        • #5
          On the other hand, Bill Gould does have this famous blog post on using Poisson rather than regress… so now I’m wondering if the two pm command is ok after all, once you take care of the weights problem.

          https://blog.stata.com/2011/08/22/us...tell-a-friend/
          -------------------------------------------
          Richard Williams
          Professor Emeritus of Sociology
          University of Notre Dame
          StataNow Version: 19.5 MP (2 processor)

          EMAIL: [email protected]
          WWW: https://academicweb.nd.edu/~rwilliam/

          Comment

          Working...
          X