Announcement

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

  • Converting regression coefficients into equation format

    I wonder if there is a way to directly output the results of a regression (of any form) into an equation form so that one can use it as part of a do file for subsequent analysis. I know that the 'estimates' command allows users to store and re-use the results for predictions and other uses, but the platform that I want to re-use the coefficients does not support using externally generated input files (such as those saved as 'estimates'); it only processes commands in the form of do files. If the regression equation I had was simple, I could have simply typed the coefficients in an equation form as part of my do file, but in my case which is a multinomial probit model has 23 coefficients for 5 categories of the dependent variable, hence over 100 coefficients altogether. Can some one help?


    Thank you

  • #2
    I would start with the fact that mlogit and other estimation commands leave the coefficients behind in the matrix e(b). Depending on how you want to use that, you can try saving that as a stata file (using svmat) and possibly export that file or writing a text-file containing those value (using the file command). What is best/most convenient depends on the fine details of how you want to use those estimates.
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thank you Maarten for the suggestion. The purpose of the exercise is to make out of sample prediction, but the problem I have is that the data on which I want to apply these coefficients on sits on a secured external platform that does not support uploading any file into the system. So what I am interested is to know if there is a way to automatically convert estimated coefficients into an equation form so that I could integrate the equation into my do file and obtain out of sample predictions. Say, for example, if I had a single independent (X) variable, and have the following coefficients form an OLS regression model: a = 1.25 and b = 0.7, I could have simply written the resulting estimates into my do file as follows: gen y = 1.25 + 0.7*X, and run the command on to the external data to obtain an out of sample point prediction (without the need to use the estimates command). But in my case I have 23 coefficients for 5 categories of the dependent variable (altogether over 100 variables), which makes it cumbersome and increases human error.

      Comment


      • #4
        You can store the regression results in a do-file.
        Code:
        sysuse auto
        regress mpg weight
        matrix m = e(b)
        local a = m[1,2]
        local b = m[1,1]
        file open dofile using "dofile.do", read write
        file write dofile "gen y = `a' + `b'*weight"
        file close dofile
        The file "dofile.do", which you can apply to the external data, contains this line:
        Code:
        gen y = 39.44028353071797 + -.0060086868119993*weight

        Comment


        • #5
          Thank you Friedrich for the suggestion.

          Comment

          Working...
          X