Announcement

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

  • #16
    Originally posted by John Mullahy View Post
    Hello Tuan. There's nothing to install. bvpmvp() is just a Mata program that calls on some other user-written Mata functions. If you don't have access to the code then send me a private Statalist message with your email address and I'll email it to you.
    Dear @John Mullahy, I try to understand how to use the bvpmvp() function. So I use the data generation code and Mata program code of bvpmvp() provided by John Mullahy, who wrote the bvpmvp() program ( Estimation of Multivariate Probit Models via Bivariate Probit, 2016). But when I use the function, the Stata report the error as

    Code:
    . mata
    ------------------------------------------------- mata (type end to exit) ------------------------------------------------
    : xn="x1 x2 x3 x4"
    
    : yn="y1 y2 y3 y4"
    
    : ic="if _n<=10000"
    
    : bv=bvpmvp(yn,xn,ic,1,.0001,1)
    equation athrho not found
                     stata():  3598  Stata returned error
                    bvpmvp():     -  function returned error
                     <istmt>:     -  function returned error
    r(3598);
    
    : end
    Does it mean there is some problem in the Mata function code?

    The data generate code is as followings (also from John Mullahy (2016)):
    Code:
    set obs 100000
    gen u=invnorm(uniform())
    
    forvalues i=1(1)8 {
    
      gen u`i'=invnorm(uniform())
    
      gen x`i'=uniform()
    
    }
    
    
    gen y1s=.5+.5*x1-.5*x2+.5*x3-.5*x4+u+u1
    
    gen y2s=-.5-.5*x1+.5*x2-.5*x3+.5*x4+.5*u+u2
    
    gen y3s=.5+.5*x1+.5*x2-.5*x3-.5*x4+u+u3
    
    gen y4s=-.5+.5*x1-.5*x2-.5*x3+.5*x4+.5*u+u4
    
    gen y5s=.5+.5*x1-.5*x2+.5*x3-.5*x4+u+u5
    
    gen y6s=-.5-.5*x1+.5*x2-.5*x3+.5*x4+.5*u+u6
    
    gen y7s=.5+.5*x1+.5*x2-.5*x3-.5*x4+u+u7
    
    gen y8s=-.5+.5*x1-.5*x2-.5*x3+.5*x4+.5*u+u8
    
    
    forvalues i=1(1)8 {
    
      gen y`i'=y`i's>0
    
    }
    
    
    gen y1o=y1
    
    replace y1o=2 if (y1s>=1 & y1s<=2)
    
    replace y1o=3 if (y1s>2)
    
    gen y2o=y2
    
    replace y2o=2 if (y2s>=1)
    
    gen y3o=y3
    
    gen y4o=y4
    
    replace y4o=2 if (y4s>=1 & y4s<=2)
    
    replace y4o=3 if (y4s>2)
    
    
    
    gen tmpxb=.25*x5-.25*x6+.25*x7-.25*x8
    
    
    
    gen y1as=.5+.5*x1-.5*x2+.5*x3-.5*x4+tmpxb+u+u1
    
    gen y2as=-.5-.5*x1+.5*x2-.5*x3+.5*x4-tmpxb+.5*u+u2
    
    gen y3as=.5+.5*x1+.5*x2-.5*x3-.5*x4+tmpxb+u+u3
    
    gen y4as=-.5+.5*x1-.5*x2-.5*x3+.5*x4-tmpxb+.5*u+u4
    
    gen y5as=.5+.5*x1-.5*x2+.5*x3-.5*x4+tmpxb+u+u5
    
    gen y6as=-.5-.5*x1+.5*x2-.5*x3+.5*x4-tmpxb+.5*u+u6
    
    gen y7as=.5+.5*x1+.5*x2-.5*x3-.5*x4+tmpxb+u+u7
    
    gen y8as=-.5+.5*x1-.5*x2-.5*x3+.5*x4-tmpxb+.5*u+u8
    
    
    
    forvalues i=1(1)8 {
    
      gen y`i'a=y`i'as>0
    
    }
    Thank you so much in advance.

    Comment


    • #17
      Stata changed the way it named some ancillary parameters (I believe when version 15 was launched), including athrho. Before running the Mata code issue the Stata command
      Code:
      version 14.0
      and then run the Mata code.

      Comment


      • #18
        Originally posted by John Mullahy View Post
        Stata changed the way it named some ancillary parameters (I believe when version 15 was launched), including athrho. Before running the Mata code issue the Stata command
        Code:
        version 14.0
        and then run the Mata code.
        Dear @John Mullahy, this is really helpful and it solves my problem! Thank you so much.

        Comment


        • #19
          I am trying to estimate a multivariate probit model. I have a large number of outcomes (9), a large number of controls (20) and nearly 1 million of observations. The command mvprobit (Capellari & Jenkins, 2003) takes too much time, so I am trying to implement the Mata based procedure bvpmvp() suggested by Mullahy (2016). I just copied the file bvpmvp.do that accompanies the Stata Journal article to my working directory. However, when I run my do file, I get the following error:
          <istmt>: 3499 bvpmvp() not found
          I hope sombody can point me what am I doing wrong. My Stata version is 16.1 (running on a Mac). I provide the following code that replicates the error:


          Code:
          /* set the working dir, where I have the data and the file bvpmvp.do */
          *cd "/myworkingdir"
          version 16.1
          set obs 500
          gen u=invnorm(uniform())
          /* gen three binary outcomes with 3 RHS vars */
          forvalues i=1(1)3 {
          gen u`i' = invnorm(uniform())
          gen x`i' = uniform()
          }
          gen y1s = 0.5 + 0.5*x1 - 0.5*x2 + 0.5*x3 + 1.0*u + u1
          gen y2s = -0.5 - 0.5*x1 + 0.5*x2 + 1.0*x3 + 0.5*u + u2
          gen y3s = 0.5 + 0.5*x1 + 0.5*x2 - 1.0*x3 + 1.0*u + u3
          forvalues i=1(1)3 {
          gen y`i' = y`i's>0
          }
          mata
          yn="y1 y2 y3"
          xn="x1 x2 x3"
          ic=""
          bv1=bvpmvp(yn,xn,ic,1,.001,1)
          end
          When I run the code above I get the following:

          Code:
           mata
          ------------------------------------------------- mata (type end to exit) -----
          : yn="y1 y2 y3"
          
          : xn="x1 x2 x3"
          
          : ic=""
          
          : bv1=bvpmvp(yn,xn,ic,1,.001,1)
                           <istmt>:  3499  bvpmvp() not found
          r(3499);
          
          : end

          References:
          Capellari & Jenkins (2003). Multivariate probit regression using simulated maximum likelihood. The Stata Journal (2003) 3, Number 3, pp. 278–294.
          https://journals.sagepub.com/doi/10....867X0300300305
          Mullahy (2016). Estimation of multivariate probit models via bivariate probit. The Stata Journal (2016) 16, Number 1, pp. 37–51.
          https://journals.sagepub.com/doi/10....867X1601600107



          Comment


          • #20
            (by mistake I wrote another post trying to edit my previous one; omit this)
            Last edited by Esteban Colla; 28 Jun 2020, 19:21.

            Comment


            • #21
              Esteban: The bvpmvp.do file doesn't run automatically from your working directory. You need to run this file then run your program.

              Also I'm not sure which version of the program you have but to be safe you should run your program under version control, using version 14.0

              Comment


              • #22
                John,
                I appreciate your answer and help.
                I added the generation of data (in order to have a dataset), and the function command at the end of the bvpmvp.do file, as follows:

                Code:
                version 14.0
                mata
                function bvpmvp(ynames,xnames,ifc,quivar,rndvar,printres) {
                /* I am omitting the code of the function for brevity */
                }
                end
                
                
                /* generation of data*/
                
                set obs 500
                gen u=invnorm(uniform())
                forvalues i=1(1)3 {
                  gen u`i' = invnorm(uniform())
                  gen x`i' = uniform()
                }
                gen y1s =  0.5 + 0.5*x1 - 0.5*x2 + 0.5*x3 + 1.0*u + u1
                gen y2s = -0.5 - 0.5*x1 + 0.5*x2 + 1.0*x3 + 0.5*u + u2
                gen y3s =  0.5 + 0.5*x1 + 0.5*x2 - 1.0*x3 + 1.0*u + u3
                forvalues i=1(1)3 {
                  gen y`i' = y`i's>0
                }
                
                /* estimation of mvprobit using bvpmvp */
                
                mata
                yn="y1 y2 y3"
                xn="x1 x2 x3"
                ic=""
                bv1=bvpmvp(yn,xn,ic,1,.001,1)
                end
                When I run the do file I get two errors. The first one appears just at the end of the definition of the function:
                Code:
                > return((tall,vall))
                > }
                variable i undeclared
                variable j undeclared
                r(3000);
                
                : 
                : end
                The second one appears when I estimate the model with the function:

                Code:
                : bv1=bvpmvp(yn,xn,ic,1,.001,1)
                                 <istmt>:  3499  bvpmvp() not found
                r(3499);
                Do you have any clue on what am I doing wrong?

                Comment


                • #23
                  Esteban: I'm not sure about this but the first thing that occurs to me is to be sure matastrict is set to off:

                  Code:
                  set matastrict off
                  mata
                  yn="y1 y2 y3"
                  xn="x1 x2 x3"
                  ic=""
                  bv1=bvpmvp(yn,xn,ic,1,.001,1)
                  end
                  The second error likely arises since the function didn't compile.

                  Comment


                  • #24
                    I just added set matastrict off at the beginning of the file and it worked. (It solved both problems.) Thanks!!
                    Code:
                    clear all
                    version 14.0
                    set matastrict off
                    mata
                    function bvpmvp(ynames,xnames,ifc,quivar,rndvar,printres) {
                    etc etc....


                    Comment


                    • #25
                      Terrific. Good luck on your project, Esteban.

                      Comment


                      • #26
                        John: Your paper at the Stata Journal and the function bvpmvp() helped a lot with the project. Thanks!
                        I have one more question related to hypothesis testing. I understand that the estimated coefficient X and its standard error SE are outcomes from the suest procedure. I want to make an inference on the significance of X. For this, I calculate the statistic Z=X/SE. As I have approximately N=1 million observations, I guess Z is asymptotically standard normal N(0,1). But I would like to know whether the theoretical distribution of Z is indeed the standard normal.
                        Last edited by Esteban Colla; 02 Jul 2020, 12:13.

                        Comment


                        • #27
                          I'm not sure about this, Esteban, but I can't imagine why Z wouldn't be asymptotially N(0,1).

                          Comment


                          • #28
                            I will discuss the best strategy to report the inference with my coauthors, but I think I will be safe if I report Z as asymptotically normal. Thanks again for your help!

                            Comment


                            • #29
                              Hi John Mullahy and others,

                              I am using stata 17.0. I was able to use this thread to debug my effort to get bvpmvp to load. It took about 15 minutes but it is now working, so thanks, everyone, especially John! By working I mean the mata code runs, no errors, and then the rest of my do-file tries to run a model. That's when it errors out. I had to set delimit to carriage return to get mata to run without error in the do-file, so then I reset it so I can more easily control commands.) Immediately after the bvpmvp command is seemingly successfully defined via mata, this is what I tried::

                              Code:
                              #delimit ;
                              bvpmvp("yvar1 yvar2 yvar3 yvar4","educ earnings sei age","if year==2010",0,.001,1) ;
                              and what I get is:

                              Code:
                              . bvpmvp("yvar1 yvar2 yvar3 yvar4","educ earnings sei age","if year==2010",0,.001,1) ;
                              command bvpmvp is unrecognized
                              I have tried it with -bv1=bvpmvp(. . .)- and as above. I have tried it with version set to 14.0 and with it left as is, which is 17.0. Regardless, the failure to recognize the bvpmvp command recurs.

                              I appreciate any guidance anyone can offer.

                              Thanks a bunch!
                              Sam

                              Comment


                              • #30
                                Sam: It appears you are trying to run bvpmvp from the Stata environment (. prompt). As such you'll need to prefix your command with "mata", i.e.

                                Code:
                                mata bvpmvp("yvar1 yvar2 yvar3 yvar4","educ earnings sei age","if year==2010",0,.001,1)

                                Comment

                                Working...
                                X