Announcement

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

  • twopm: Two Part Models

    I am using Stata 15 MP and my analytic data set is a geographic region-year panel, for the years 2000-2011, and 48 African countries (n=8,928).

    I am estimating a two part model using the twopm command. I do understand that this is a user written command (The Stata Journal, Vol 15, No 1 pp 3-20) and that I may need to follow up with the authors. I am posting here in case others have experience with this particular problem.

    I am able to successfully estimate the first and second part of the model for the specification as:

    Code:
    twopm all_aid n_birth i.Capital c.log_NTL c.n_pop c.area i.ports i.oil c.log_mines c.road_density i.n_polity i.n_year, firstpart(probit) secondpart(regress, log)
    However, when I add in the i.country fixed effects (n=48) and run this specification:
    Code:
    twopm all_aid n_birth i.Capital c.log_NTL c.n_pop c.area i.ports i.oil c.log_mines c.road_density i.n_polity i.n_year i.country, firstpart(probit) secondpart(regress, log)
    I get the following error:
    Code:
                           *:  3200  conformability error
                    _resid():     -  function returned error
                     <istmt>:     -  function returned error
    I think the problem is related to the matrix construction and would appreciate any suggestions about next steps.

    Below is a subset of the data that I am using in the analysis.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float n_birth byte Capital float(log_NTL n_pop area ports oil log_mines road_density n_polity) int n_year float(country log_all) double all_aid
    0 0  2.2023542  7.096685   6260654592 0 0         0  .05351823 2 2000 1         0            0
    0 0  2.2023542  7.096685   6260654592 0 0         0  .05351823 2 2001 1         0            0
    0 0  2.2023542  7.096685   6260654592 0 0         0  .05351823 2 2002 1         0            0
    0 0  2.2023542  7.096685   6260654592 0 0         0  .05351823 2 2003 1         0            0
    0 0  2.2023542  7.096685   6260654592 0 0         0  .05351823 2 2004 1         0            0
    0 0  2.2023542  7.096685   6260654592 0 0         0  .05351823 2 2005 1         0            0
    0 0  2.2023542  7.096685   6260654592 0 0         0  .05351823 2 2006 1         0            0
    0 0  2.2023542  7.096685   6260654592 0 0         0  .05351823 2 2007 1         0            0
    0 0  2.2023542  7.096685   6260654592 0 0         0  .05351823 2 2008 1         0            0
    0 0  2.2023542  7.096685   6260654592 0 0         0  .05351823 2 2009 1         0            0
    0 0  2.2023542  7.096685   6260654592 0 0         0  .05351823 2 2010 1         0            0
    0 0  2.2023542  7.096685   6260654592 0 0         0  .05351823 2 2011 1         0            0
    0 0  2.2067032 3.4792726   3235284992 1 0 1.0986123  .07385414 2 2000 1         0            0
    0 0  2.2067032 3.4792726   3235284992 1 0 1.0986123  .07385414 2 2001 1         0            0
    0 0  2.2067032 3.4792726   3235284992 1 0 1.0986123  .07385414 2 2002 1         0            0
    0 0  2.2067032 3.4792726   3235284992 1 0 1.0986123  .07385414 2 2003 1         0            0
    0 0  2.2067032 3.4792726   3235284992 1 0 1.0986123  .07385414 2 2004 1         0            0
    0 0  2.2067032 3.4792726   3235284992 1 0 1.0986123  .07385414 2 2005 1         0            0
    0 0  2.2067032 3.4792726   3235284992 1 0 1.0986123  .07385414 2 2006 1         0            0
    0 0  2.2067032 3.4792726   3235284992 1 0 1.0986123  .07385414 2 2007 1         0            0
    0 0  2.2067032 3.4792726   3235284992 1 0 1.0986123  .07385414 2 2008 1         0            0
    0 0  2.2067032 3.4792726   3235284992 1 0 1.0986123  .07385414 2 2009 1         0            0
    0 0  2.2067032 3.4792726   3235284992 1 0 1.0986123  .07385414 2 2010 1         0            0
    0 0  2.2067032 3.4792726   3235284992 1 0 1.0986123  .07385414 2 2011 1         0            0
    0 0 -2.0366273  3.407414  4.75507e+11 0 1         0 .013278006 2 2000 1         0            0
    0 0 -2.0366273  3.407414  4.75507e+11 0 1         0 .013278006 2 2001 1         0            0
    0 0 -2.0366273  3.407414  4.75507e+11 0 1         0 .013278006 2 2002 1         0            0
    0 0 -2.0366273  3.407414  4.75507e+11 0 1         0 .013278006 2 2003 1         0            0
    0 0 -2.0366273  3.407414  4.75507e+11 0 1         0 .013278006 2 2004 1         0            0
    0 0 -2.0366273  3.407414  4.75507e+11 0 1         0 .013278006 2 2005 1         0            0
    0 0 -2.0366273  3.407414  4.75507e+11 0 1         0 .013278006 2 2006 1         0            0
    0 0 -2.0366273  3.407414  4.75507e+11 0 1         0 .013278006 2 2007 1         0            0
    0 0 -2.0366273  3.407414  4.75507e+11 0 1         0 .013278006 2 2008 1         0            0
    0 0 -2.0366273  3.407414  4.75507e+11 0 1         0 .013278006 2 2009 1         0            0
    0 0 -2.0366273  3.407414  4.75507e+11 0 1         0 .013278006 2 2010 1         0            0
    0 0 -2.0366273  3.407414  4.75507e+11 0 1         0 .013278006 2 2011 1         0            0
    0 1  4.0834794  26.81683   1073996160 0 0         0   .1938671 2 2000 1         0            0
    0 1  4.0834794  26.81683   1073996160 0 0         0   .1938671 2 2001 1         0            0
    0 1  4.0834794  26.81683   1073996160 0 0         0   .1938671 2 2002 1         0            0
    0 1  4.0834794  26.81683   1073996160 0 0         0   .1938671 2 2003 1 13.095222 486610.65625
    0 1  4.0834794  26.81683   1073996160 0 0         0   .1938671 2 2004 1         0            0
    0 1  4.0834794  26.81683   1073996160 0 0         0   .1938671 2 2005 1         0            0
    0 1  4.0834794  26.81683   1073996160 0 0         0   .1938671 2 2006 1         0            0
    0 1  4.0834794  26.81683   1073996160 0 0         0   .1938671 2 2007 1         0            0
    0 1  4.0834794  26.81683   1073996160 0 0         0   .1938671 2 2008 1         0            0
    0 1  4.0834794  26.81683   1073996160 0 0         0   .1938671 2 2009 1         0            0
    0 1  4.0834794  26.81683   1073996160 0 0         0   .1938671 2 2010 1 17.533833     41195244
    0 1  4.0834794  26.81683   1073996160 0 0         0   .1938671 2 2011 1         0            0
    0 0   2.740843  5.686339   1978018688 1 0 2.3025851  .09994795 2 2000 1         0            0
    0 0   2.740843  5.686339   1978018688 1 0 2.3025851  .09994795 2 2001 1         0            0
    0 0   2.740843  5.686339   1978018688 1 0 2.3025851  .09994795 2 2002 1         0            0
    0 0   2.740843  5.686339   1978018688 1 0 2.3025851  .09994795 2 2003 1         0            0
    0 0   2.740843  5.686339   1978018688 1 0 2.3025851  .09994795 2 2004 1         0            0
    0 0   2.740843  5.686339   1978018688 1 0 2.3025851  .09994795 2 2005 1         0            0
    0 0   2.740843  5.686339   1978018688 1 0 2.3025851  .09994795 2 2006 1         0            0
    0 0   2.740843  5.686339   1978018688 1 0 2.3025851  .09994795 2 2007 1         0            0
    0 0   2.740843  5.686339   1978018688 1 0 2.3025851  .09994795 2 2008 1         0            0
    0 0   2.740843  5.686339   1978018688 1 0 2.3025851  .09994795 2 2009 1         0            0
    0 0   2.740843  5.686339   1978018688 1 0 2.3025851  .09994795 2 2010 1         0            0
    0 0   2.740843  5.686339   1978018688 1 0 2.3025851  .09994795 2 2011 1         0            0
    0 0  -1.877278  2.436817 1.917303e+11 0 1  .6931472 .020742806 2 2000 1         0            0
    0 0  -1.877278  2.436817 1.917303e+11 0 1  .6931472 .020742806 2 2001 1         0            0
    0 0  -1.877278  2.436817 1.917303e+11 0 1  .6931472 .020742806 2 2002 1         0            0
    0 0  -1.877278  2.436817 1.917303e+11 0 1  .6931472 .020742806 2 2003 1         0            0
    0 0  -1.877278  2.436817 1.917303e+11 0 1  .6931472 .020742806 2 2004 1         0            0
    0 0  -1.877278  2.436817 1.917303e+11 0 1  .6931472 .020742806 2 2005 1         0            0
    0 0  -1.877278  2.436817 1.917303e+11 0 1  .6931472 .020742806 2 2006 1         0            0
    0 0  -1.877278  2.436817 1.917303e+11 0 1  .6931472 .020742806 2 2007 1         0            0
    0 0  -1.877278  2.436817 1.917303e+11 0 1  .6931472 .020742806 2 2008 1         0            0
    0 0  -1.877278  2.436817 1.917303e+11 0 1  .6931472 .020742806 2 2009 1         0            0
    0 0  -1.877278  2.436817 1.917303e+11 0 1  .6931472 .020742806 2 2010 1         0            0
    0 0  -1.877278  2.436817 1.917303e+11 0 1  .6931472 .020742806 2 2011 1         0            0
    0 0   2.432754 8.9758415   4489071616 1 0         0  .11833785 2 2000 1         0            0
    0 0   2.432754 8.9758415   4489071616 1 0         0  .11833785 2 2001 1         0            0
    0 0   2.432754 8.9758415   4489071616 1 0         0  .11833785 2 2002 1         0            0
    0 0   2.432754 8.9758415   4489071616 1 0         0  .11833785 2 2003 1         0            0
    0 0   2.432754 8.9758415   4489071616 1 0         0  .11833785 2 2004 1         0            0
    0 0   2.432754 8.9758415   4489071616 1 0         0  .11833785 2 2005 1         0            0
    0 0   2.432754 8.9758415   4489071616 1 0         0  .11833785 2 2006 1         0            0
    0 0   2.432754 8.9758415   4489071616 1 0         0  .11833785 2 2007 1         0            0
    0 0   2.432754 8.9758415   4489071616 1 0         0  .11833785 2 2008 1         0            0
    0 0   2.432754 8.9758415   4489071616 1 0         0  .11833785 2 2009 1         0            0
    0 0   2.432754 8.9758415   4489071616 1 0         0  .11833785 2 2010 1         0            0
    0 0   2.432754 8.9758415   4489071616 1 0         0  .11833785 2 2011 1         0            0
    0 0  1.8802855 10.290612  16381642752 0 0  .6931472  .08080617 2 2000 1         0            0
    0 0  1.8802855 10.290612  16381642752 0 0  .6931472  .08080617 2 2001 1         0            0
    0 0  1.8802855 10.290612  16381642752 0 0  .6931472  .08080617 2 2002 1         0            0
    0 0  1.8802855 10.290612  16381642752 0 0  .6931472  .08080617 2 2003 1         0            0
    0 0  1.8802855 10.290612  16381642752 0 0  .6931472  .08080617 2 2004 1         0            0
    0 0  1.8802855 10.290612  16381642752 0 0  .6931472  .08080617 2 2005 1         0            0
    0 0  1.8802855 10.290612  16381642752 0 0  .6931472  .08080617 2 2006 1         0            0
    0 0  1.8802855 10.290612  16381642752 0 0  .6931472  .08080617 2 2007 1         0            0
    0 0  1.8802855 10.290612  16381642752 0 0  .6931472  .08080617 2 2008 1         0            0
    0 0  1.8802855 10.290612  16381642752 0 0  .6931472  .08080617 2 2009 1         0            0
    0 0  1.8802855 10.290612  16381642752 0 0  .6931472  .08080617 2 2010 1         0            0
    0 0  1.8802855 10.290612  16381642752 0 0  .6931472  .08080617 2 2011 1         0            0
    0 0    .636917  6.251555  28324433920 0 0 1.0986123  .05668944 2 2000 1         0            0
    0 0    .636917  6.251555  28324433920 0 0 1.0986123  .05668944 2 2001 1         0            0
    0 0    .636917  6.251555  28324433920 0 0 1.0986123  .05668944 2 2002 1         0            0
    0 0    .636917  6.251555  28324433920 0 0 1.0986123  .05668944 2 2003 1         0            0
    end




  • #2
    I've only occasionally used -twopm-, but here are some thoughts:

    1) What about trying to run a much simpler model with and without the country fixed effect as a means to diagnosis? I'd start with something like:
    Code:
    twopm all_aid n_birth i.n_year i.country, firstpart(probit) secondpart(regress, log)
    and then progressively try more predictors until a problem occurs. Perhaps you've tried this.

    2) Are you giving us absolutely all the error output you got? What you have shown would indicate that the failure happened before even the probit completed. That would make me wonder whether the combination of year and country with your other variables results in some combination with an exact prediction on which the probit chokes. Can you even get the probit to run on its own? If not, can you get some simpler version, per 1), to run?


    Comment


    • #3
      Thank you!

      Following up on your specific suggestions:

      1. Correct. I did try running as a much simpler model in which I slowly added in covariates determining that the specification choked when adding in the country FE

      2. Following up on your suggestion #2, I did the following:

      Code:
      set trace on
      and received the following diagnostic information

      Code:
          = mata: resid = _resid("__00000Q", " n_birth i.Capital log_NTL n_pop area i.ports i.oil log_mines road_density i.n_polity i.n_year i.country", "__000002", "__00001D")
                             *:  3200  conformability error
                      _resid():     -  function returned error
                       <istmt>:     -  function returned error
      Which lead me to understanding you were correct with suggestion #2. There were 3 countries with no aid values and therefore when I added in the country FE it was a perfect prediction (resulting in the error). I am new to the output with the twopm and now see how I could have discerned that sooner given the error message.

      Many many thanks. I was so focused on that matrix and it was something much more simple (and easy to handle).

      Carrie

      Comment

      Working...
      X