Announcement

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

  • Regression with Stored Coefficients

    Hello I have a regression of treatment on some individual characteristics in data set 1:

    reg treatment1 female_1 age_1.... etc

    I would like to use stored coefficients of this regression:

    _b[female_1], _beta[age_1] to be able to calculate the probability of being treated in another data set by using the individual characteristics in data set 2:

    basically it would be like:

    treatment2=_b[constant]_b[female_1]*female_2+ _beta[age_1]*age_2+....

    How to calculate this outcome in an estimation logic? i.e. as if I am calculating inverse probability?

    Thanks in advance



  • #2
    One way could be predict. See point 9 on page 1, and then pages 5-7 in https://www.stata.com/manuals/rpredict.pdf.

    Here is a short example:

    Code:
    sysuse auto, clear
    keep if _n <= 37 // Keep only the first half (aka, pretend to be 1st data set)
    regress mpg price trunk // Run the regression
    
    sysuse auto, clear
    keep if _n >= 38 // Use only the second half of the data (aka, 2nd data set)
    predict yhat // Apply the old regression to compute y hat
    
    * Double check:
    generate yhat2 = 31.50203 - 0.0004055*price - 0.6443269*trunk
    Results:

    Code:
         +---------------------+
         |     yhat      yhat2 |
         |---------------------|
      1. | 16.63252    16.6326 |
      2. |   20.786   20.78606 |
      3. | 23.35763   23.35769 |
      4. | 16.34288   16.34303 |
      5. | 22.53001   22.53008 |
         |---------------------|
      6. | 22.62003    22.6201 |
      7. | 18.73096   18.73102 |
      8. | 23.71725   23.71734 |
      9. | 19.54641   19.54647 |
     10. | 16.26432    16.2644 |
         +---------------------+

    Comment


    • #3
      Mehlika:
      welcome to this forum.
      -statsby- is another option (warning: use -statsby- on a copy of your original dataset):
      Code:
      . use "C:\Program Files\Stata17\ado\base\a\auto.dta"
      (1978 automobile data)
      
      . help statsby
      
      . statsby _b, by(foreign) verbose nodots: regress price weight length mpg
      
            Command: regress price weight length mpg
          _b_weight: _b[weight]
          _b_length: _b[length]
             _b_mpg: _b[mpg]
            _b_cons: _b[_cons]
                 By: foreign
      
      
      . list
      
           +-------------------------------------------------------+
           |  foreign   _b_wei~t   _b_length     _b_mpg    _b_cons |
           |-------------------------------------------------------|
        1. | Domestic   6.767233   -109.9518   142.7663   2359.475 |
        2. |  Foreign   4.784841    13.39052   -18.4072   -6497.49 |
           +-------------------------------------------------------+
      
      .
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment


      • #4
        Thank you both Ken and Carlo

        Comment

        Working...
        X