Announcement

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

  • STATA/MATA as a develop?

    Hi all,

    I know that, some econometricians would like to write STATA programs of their econometric models. Currently, I am doing practice in this field. To the best of my knowledge, people usually write the main function in MATA and let MATA to pass the results back to STATA. However, for the built-in STATA functions, as I look at their codes, it seems like that most of them are written in STATA (without MATA). I am wondering whether you guys have some experiences in this field and I would appreciate for your sharing, because I am still new to STATA (less than 1 year).

    Another problem when using STATA/MATA to develop econometric programming is that the codes take much more time to return results than other software, for example, MATLAB, Python, etc.. So I also want to know how to make the codes run faster.

    I would very much appreciate for any suggestions and advice.

  • #2
    Stata and Mata are different tools. Neither is better or worse than the other, you just need to use the right tool for the job. As to making code quicker, we cannot comment on that without seeing your code.
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thank you. Well, my question is too general. Let me state it in a more specific way. I am wondering for the following basic operations, which one is faster, STATA or MATA?

      1. looping
      2. matrix operations
      ....

      Also, I am wondering whether there is a difference between the time used when passing parameters from STATA to MATA and the time used when passing parameters from MATA to STATA.

      Thanks

      Comment


      • #4
        I have to test a unit root test with my panel data. I'm begining in Statistics, 1 have 100 Moroccan cities from 1982 to 2014. I want to examine if my Ln(size_cities) variable has unit roots or not. When I set the (xtunitroot llc ln(size_cities) , lags(aic 10)) command in STATA (12). Stata said that “Levin-Lin-Chiu test cannot have gaps in data”?

        Comment


        • #5
          A common mistake for new programers is to loop over observations in your dataset. This can often be avoided, which leads to a significant gain in speed. Other than that, the speed of the loop depends critically on what you do inside the loop.

          Mata is the obvious tool for matrix operations, but often there is an equivalent way of doing the same thing through operations directly on the data.

          So your question is still way too broad.
          ---------------------------------
          Maarten L. Buis
          University of Konstanz
          Department of history and sociology
          box 40
          78457 Konstanz
          Germany
          http://www.maartenbuis.nl
          ---------------------------------

          Comment


          • #6
            Oumar ELHAMDANI you need to start your own question, and not add a question to an unrelated question.

            To do so press the "new topic" button that appears on top the list of topics:

            Click image for larger version

Name:	Graph.png
Views:	1
Size:	88.2 KB
ID:	1343847


            Moreover, your question belongs in the General forum, not the Mata forum.
            ---------------------------------
            Maarten L. Buis
            University of Konstanz
            Department of history and sociology
            box 40
            78457 Konstanz
            Germany
            http://www.maartenbuis.nl
            ---------------------------------

            Comment


            • #7
              Thanks Maarten

              Comment


              • #8
                Ingrid Qiu Mata will generally be faster since it is a compiled language (e.g., the code is stored/saved in a much lower level language that does not need to be interpreted repeatedly). I'm surprised that you're finding Python to be that much faster since it definitely is not the language of choice for performance optimization (e.g., C, C++, FORTRAN, and Java all outperform Python for the same reason Mata will typically out perform Stata).

                Comment


                • #9
                  Originally posted by wbuchanan View Post
                  Ingrid Qiu Mata will generally be faster since it is a compiled language (e.g., the code is stored/saved in a much lower level language that does not need to be interpreted repeatedly). I'm surprised that you're finding Python to be that much faster since it definitely is not the language of choice for performance optimization (e.g., C, C++, FORTRAN, and Java all outperform Python for the same reason Mata will typically out perform Stata).
                  Thank you for illustrating the underlying mechanism. Recently, I met a somewhat interesting problem but I cannot explain. I convert a MATLAB version of quantile regression code into MATA. But it runs much smaller than the STATA built-in -qreg command. (I repeatedly run quantile regressions 100 times and compared the time used of each version of quantile regression.) Is it because the STATA code is optimized? I am quite curious about this point.

                  Comment


                  • #10
                    qreg calls _qreg, which is built-in, meaning that it is written in C.
                    ---------------------------------
                    Maarten L. Buis
                    University of Konstanz
                    Department of history and sociology
                    box 40
                    78457 Konstanz
                    Germany
                    http://www.maartenbuis.nl
                    ---------------------------------

                    Comment


                    • #11
                      Originally posted by Maarten Buis View Post
                      qreg calls _qreg, which is built-in, meaning that it is written in C.
                      Thanks Maarten. No wonder when I look at the source code of qreg, I failed to find the function _qreg. So where is _qreg stored?

                      Comment


                      • #12
                        It is part of the Stata binary, so the source is not openly available. Additionally, the terms of agreement with nearly all proprietary software does not give users permission to attempt to decompile the binary to reverse engineer things. Some users (e.g., Matthew Baker) have done some work with these types of models and could likely give you some advice on their approach. The other options would basically involve finding or writing a C/Java plugin if you needed better performance than what you can get from Mata (although there are no guarantees that this would improve performance either).

                        Comment


                        • #13
                          Thank you for illustrating.

                          Comment

                          Working...
                          X