Announcement

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

  • Saving regression coefficients from 3 regressions in one same dataset

    I have the dataset that include further below. I ran the following three regressions on this dataset:

    HTML Code:
    di "model1"
    reg logvalue loc_two ib2.reg_no ib2.iname_no, baselevels
    
    di "model2"
    reg logvalue ib2.reg_no#ib1.loc_three ib2.iname_no, baselevels
    
    di "model3"
    reg logvalue ib2.reg_no#ib1.loc_three ib2.iname_no, baselevels
    How can I save the coefficients in each regression into one dataset following the format seen in the picture below? Notice that I would like to include the loc_avg_byreg and loc_avg_byreg_bylowmedhigh variables in this pseudo-collapsed dataset.
    Click image for larger version

Name:	example.JPG
Views:	1
Size:	57.2 KB
ID:	1507228



    Any help or pointers would be extremely valuable.

    -------------------------

    My dataset extract is below:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str3 iso int icode str5 iname double logvalue str3 reg byte loc long(loc_two loc_three reg_no) float(loc_avg_byreg loc_avg_byreg_bylowmedhigh) long iname_no
    "SDN" 121 "rowh"             5.37338 "AFR" 27 1 1 1  38.49152      38.5 2
    "TGO" 121 "rowh"            4.524546 "AFR"  8 1 1 1  38.49152      38.5 2
    "TCD" 131 "singh"           5.021682 "AFR" 31 1 1 1  38.49152      38.5 3
    "MOZ" 111 "apt"             .1282708 "AFR" 70 1 1 1  38.49152      38.5 1
    "SDN" 111 "apt"             6.988078 "AFR" 11 1 1 1  38.49152      38.5 1
    "ZWE" 111 "apt"             9.015048 "AFR" 24 1 1 1  38.49152      38.5 1
    "TZA" 121 "rowh"            6.139424 "AFR" 21 1 1 1  38.49152      38.5 2
    "GIN" 131 "singh"           4.866584 "AFR" 19 1 1 1  38.49152      38.5 3
    "CAF" 121 "rowh"             6.62749 "AFR" 69 1 1 1  38.49152      38.5 2
    "MOZ" 121 "rowh"           -.0105818 "AFR" 28 1 1 1  38.49152      38.5 2
    "COM" 131 "singh"            6.98497 "AFR" 27 1 1 1  38.49152      38.5 3
    "ZWE" 121 "rowh"           10.278447 "AFR" 61 1 1 1  38.49152      38.5 2
    "BFA" 131 "singh"  6.457775999999999 "AFR"  3 1 1 1  38.49152      38.5 3
    "MWI" 121 "rowh"            5.498448 "AFR" 57 1 1 1  38.49152      38.5 2
    "CAF" 111 "apt"            15.122898 "AFR" 72 1 1 1  38.49152      38.5 1
    "TCD" 121 "rowh"             5.95384 "AFR" 60 1 1 1  38.49152      38.5 2
    "MLI" 111 "apt"             4.794288 "AFR" 19 1 1 1  38.49152      38.5 1
    "TGO" 131 "singh"            4.50364 "AFR" 75 1 1 1  38.49152      38.5 3
    "MDG" 121 "rowh"            9.989835 "AFR"  5 1 1 1  38.49152      38.5 2
    "MWI" 111 "apt"             6.311838 "AFR" 68 1 1 1  38.49152      38.5 1
    "TZA" 111 "apt"            14.846439 "AFR" 49 1 1 1  38.49152      38.5 1
    "LSO" 111 "apt"              7.48737 "AFR" 39 1 1 1  38.49152      38.5 1
    "BFA" 111 "apt"              5.45868 "AFR" 12 1 1 1  38.49152      38.5 1
    "ZWE" 131 "singh"           9.559737 "AFR" 69 1 1 1  38.49152      38.5 3
    "BWA" 111 "apt"            12.934521 "AFR" 16 2 2 1  38.49152      27.2 1
    "STP" 111 "apt"   12.508428000000002 "AFR" 50 2 2 1  38.49152      27.2 1
    "TUN" 121 "rowh"   7.394730000000001 "AFR" 26 2 2 1  38.49152      27.2 2
    "DJI" 131 "singh"           7.753636 "AFR" 40 2 2 1  38.49152      27.2 3
    "STP" 121 "rowh"            7.487616 "AFR"  4 2 2 1  38.49152      27.2 2
    "EGY" 121 "rowh"            5.260737 "AFR" 73 1 3 1  38.49152      34.4 2
    "COG" 111 "apt"            10.679106 "AFR" 24 2 3 1  38.49152      34.4 1
    "ZAF" 131 "singh"           6.535342 "AFR"  5 2 3 1  38.49152      34.4 3
    "GNB" 131 "singh"           5.685435 "AFR" 66 1 3 1  38.49152      34.4 3
    "SLE" 111 "apt"             .4158218 "AFR" 25 1 3 1  38.49152      34.4 1
    "NGA" 121 "rowh"            8.017478 "AFR" 29 1 3 1  38.49152      34.4 2
    "SLE" 131 "singh"            .108217 "AFR" 70 1 3 1  38.49152      34.4 3
    "CMR" 131 "singh"           3.327538 "AFR"  0 2 3 1  38.49152      34.4 3
    "MRT" 131 "singh"           4.600688 "AFR"  1 2 3 1  38.49152      34.4 3
    "CIV" 121 "rowh"            8.939619 "AFR" 62 1 3 1  38.49152      34.4 2
    "CPV" 131 "singh" 13.566194999999999 "AFR" 23 2 3 1  38.49152      34.4 3
    "ZMB" 121 "rowh"             4.65996 "AFR" 16 1 3 1  38.49152      34.4 2
    "COD" 121 "rowh"  10.213868999999999 "AFR" 20 1 3 1  38.49152      34.4 2
    "GMB" 131 "singh"            5.26998 "AFR" 55 2 3 1  38.49152      34.4 3
    "GMB" 121 "rowh"            3.700236 "AFR"  9 2 3 1  38.49152      34.4 2
    "GNB" 121 "rowh"            3.811196 "AFR" 26 1 3 1  38.49152      34.4 2
    "LBR" 131 "singh"          -.9756258 "AFR" 44 1 3 1  38.49152      34.4 3
    "GHA" 111 "apt"             2.187604 "AFR" 67 2 3 1  38.49152      34.4 1
    "CMR" 121 "rowh"  5.9158740000000005 "AFR" 61 2 3 1  38.49152      34.4 2
    "GHA" 121 "rowh"             2.74744 "AFR" 12 2 3 1  38.49152      34.4 2
    "RWA" 131 "singh"                  . "AFR" 51 . . 1  38.49152      52.3 3
    "MDG" 111 "apt"                    . "AFR" 61 . . 1  38.49152      52.3 1
    "NER" 131 "singh"                  . "AFR" 66 . . 1  38.49152      52.3 3
    "MAR" 111 "apt"                    . "AFR" 22 . . 1  38.49152      52.3 1
    "KEN" 131 "singh"                  . "AFR" 62 . . 1  38.49152      52.3 3
    "RWA" 121 "rowh"                   . "AFR" 37 . . 1  38.49152      52.3 2
    "GNQ" 121 "rowh"                   . "AFR" 57 . . 1  38.49152      52.3 2
    "NER" 121 "rowh"                   . "AFR" 52 . . 1  38.49152      52.3 2
    "NER" 111 "apt"                    . "AFR" 60 . . 1  38.49152      52.3 1
    "KEN" 111 "apt"                    . "AFR" 55 . . 1  38.49152      52.3 1
    "LKA" 121 "rowh"            5.467266 "ASS"  5 1 1 2  39.92593      35.2 2
    "NPL" 131 "singh"           5.685594 "ASS" 66 1 1 2  39.92593      35.2 3
    "LAO" 111 "apt"            13.746132 "ASS" 38 1 1 2  39.92593      35.2 1
    "NPL" 121 "rowh"            9.361314 "ASS" 23 1 1 2  39.92593      35.2 2
    "VNM" 111 "apt"            12.520692 "ASS" 69 1 1 2  39.92593      35.2 1
    "KHM" 131 "singh"           7.321506 "ASS" 63 1 1 2  39.92593      35.2 3
    "PAK" 121 "rowh"           10.092891 "ASS"  8 1 1 2  39.92593      35.2 2
    "IND" 131 "singh"            3.48847 "ASS"  2 1 1 2  39.92593      35.2 3
    "BGD" 111 "apt"             5.834018 "ASS"  6 1 1 2  39.92593      35.2 1
    "PAK" 131 "singh" 10.317051000000001 "ASS" 72 1 1 2  39.92593      35.2 3
    "MYS" 111 "apt"             7.726392 "ASS" 62 2 2 2  39.92593      27.2 1
    "HKG" 111 "apt"            17.524068 "ASS" 25 2 2 2  39.92593      27.2 1
    "SGP" 131 "singh"          16.799154 "ASS" 16 2 2 2  39.92593      27.2 3
    "BRN" 131 "singh"           8.270946 "ASS"  6 2 2 2  39.92593      27.2 3
    "MYS" 121 "rowh"            6.677806 "ASS" 27 2 2 2  39.92593      27.2 2
    "FJI" 131 "singh"          11.950464 "ASS" 31 2 3 2  39.92593  40.33333 3
    "CHN" 121 "rowh"            8.909274 "ASS" 32 2 3 2  39.92593  40.33333 2
    "PHL" 121 "rowh"            8.398322 "ASS" 58 1 3 2  39.92593  40.33333 2
    "MDV" 121 "rowh"                   . "ASS" 61 . . 2  39.92593  52.11111 2
    "IND" 121 "rowh"                   . "ASS" 63 . . 2  39.92593  52.11111 2
    "MDV" 111 "apt"                    . "ASS" 51 . . 2  39.92593  52.11111 1
    "SGP" 121 "rowh"                   . "ASS" 38 . . 2  39.92593  52.11111 2
    "TWN" 131 "singh"                  . "ASS" 37 . . 2  39.92593  52.11111 3
    "SGP" 111 "apt"                    . "ASS" 49 . . 2  39.92593  52.11111 1
    "THA" 131 "singh"                  . "ASS" 52 . . 2  39.92593  52.11111 3
    "BRN" 121 "rowh"                   . "ASS" 66 . . 2  39.92593  52.11111 2
    "BTN" 131 "singh"                  . "ASS" 52 . . 2  39.92593  52.11111 3
    "TUR" 131 "singh"           9.097641 "EUR" 24 2 2 3  34.82927        28 3
    "ESP" 111 "apt"             8.816412 "EUR"  9 2 2 3  34.82927        28 1
    "CYP" 131 "singh"          11.444343 "EUR"  7 2 2 3  34.82927        28 3
    "DEU" 111 "apt"             8.927552 "EUR" 58 2 2 3  34.82927        28 1
    "CZE" 111 "apt"             6.732264 "EUR" 15 2 2 3  34.82927        28 1
    "BGR" 111 "apt"             7.344314 "EUR" 10 2 2 3  34.82927        28 1
    "ISL" 131 "singh"          14.261076 "EUR" 73 2 2 3  34.82927        28 3
    "FRA" 111 "apt"             9.032362 "EUR" 28 2 2 3  34.82927        28 1
    "ROU" 131 "singh"           7.742768 "EUR" 43 2 3 3  34.82927     40.25 3
    "AUT" 131 "singh"           8.639694 "EUR" 68 2 3 3  34.82927     40.25 3
    "IRL" 111 "apt"   15.145686000000001 "EUR" 16 2 3 3  34.82927     40.25 1
    "PRT" 111 "apt"   12.365462999999998 "EUR" 34 2 3 3  34.82927     40.25 1
    "KOR" 111 "apt"                    . "EUR" 71 . . 3  34.82927  35.96552 1
    "USA" 131 "singh"                  . "EUR" 44 . . 3  34.82927  35.96552 3
    "CAN" 111 "apt"                    . "EUR" 74 . . 3  34.82927  35.96552 1
    "MNE" 111 "apt"                    . "EUR" 32 . . 3  34.82927  35.96552 1
    "CAN" 131 "singh"                  . "EUR" 24 . . 3  34.82927  35.96552 3
    "FIN" 111 "apt"                    . "EUR" 21 . . 3  34.82927  35.96552 1
    "ALB" 131 "singh"                  . "EUR" 16 . . 3  34.82927  35.96552 3
    "AUS" 111 "apt"                    . "EUR" 22 . . 3  34.82927  35.96552 1
    "ISR" 131 "singh"                  . "EUR" 14 . . 3  34.82927  35.96552 3
    "GEO" 131 "singh"                  . "EUR" 60 . . 3  34.82927  35.96552 3
    "ALB" 111 "apt"                    . "EUR"  0 . . 3  34.82927  35.96552 1
    "RUS" 131 "singh"                  . "EUR" 17 . . 3  34.82927  35.96552 3
    "JPN" 111 "apt"                    . "EUR" 47 . . 3  34.82927  35.96552 1
    "NZL" 111 "apt"                    . "EUR" 60 . . 3  34.82927  35.96552 1
    "MLT" 111 "apt"                    . "EUR" 26 . . 3  34.82927  35.96552 1
    "LTU" 111 "apt"                    . "EUR" 15 . . 3  34.82927  35.96552 1
    "GEO" 111 "apt"                    . "EUR" 38 . . 3  34.82927  35.96552 1
    "CRI" 131 "singh"                  . "EUR" 66 . . 3  34.82927  35.96552 3
    "LVA" 111 "apt"                    . "EUR" 42 . . 3  34.82927  35.96552 1
    "MKD" 111 "apt"                    . "EUR"  3 . . 3  34.82927  35.96552 1
    "SVN" 131 "singh"                  . "EUR" 22 . . 3  34.82927  35.96552 3
    "JPN" 131 "singh"                  . "EUR" 67 . . 3  34.82927  35.96552 3
    "HRV" 131 "singh"                  . "EUR" 69 . . 3  34.82927  35.96552 3
    "SVK" 111 "apt"                    . "EUR" 37 . . 3  34.82927  35.96552 1
    "NLD" 111 "apt"                    . "EUR" 45 . . 3  34.82927  35.96552 1
    "POL" 131 "singh"                  . "EUR" 29 . . 3  34.82927  35.96552 3
    "MLT" 131 "singh"                  . "EUR" 18 . . 3  34.82927  35.96552 3
    "CRI" 111 "apt"                    . "EUR" 50 . . 3  34.82927  35.96552 1
    "SVK" 131 "singh"                  . "EUR" 14 . . 3  34.82927  35.96552 3
    "DOM" 121 "rowh"            7.294905 "LAC"  4 2 2 4 37.384617         4 2
    "VCT" 111 "apt"            10.440363 "LAC" 25 2 3 4 37.384617 27.666666 1
    "ECU" 111 "apt"            12.602373 "LAC" 38 2 3 4 37.384617 27.666666 1
    "HND" 111 "apt"            13.824459 "LAC" 20 2 3 4 37.384617 27.666666 1
    "CYM" 111 "apt"                    . "LAC" 58 . . 4 37.384617  40.22727 1
    "BMU" 111 "apt"                    . "LAC" 36 . . 4 37.384617  40.22727 1
    "CUW" 111 "apt"                    . "LAC" 31 . . 4 37.384617  40.22727 1
    "GUY" 111 "apt"                    . "LAC" 35 . . 4 37.384617  40.22727 1
    "ABW" 121 "rowh"                   . "LAC" 58 . . 4 37.384617  40.22727 2
    "BON" 121 "rowh"                   . "LAC" 20 . . 4 37.384617  40.22727 2
    "MSR" 131 "singh"                  . "LAC" 53 . . 4 37.384617  40.22727 3
    "ABW" 131 "singh"                  . "LAC"  0 . . 4 37.384617  40.22727 3
    "BOL" 121 "rowh"                   . "LAC" 25 . . 4 37.384617  40.22727 2
    "BRB" 121 "rowh"                   . "LAC" 11 . . 4 37.384617  40.22727 2
    "NIC" 111 "apt"                    . "LAC" 73 . . 4 37.384617  40.22727 1
    "PRY" 111 "apt"                    . "LAC" 32 . . 4 37.384617  40.22727 1
    "GUY" 131 "singh"                  . "LAC" 72 . . 4 37.384617  40.22727 3
    "PAN" 121 "rowh"                   . "LAC" 56 . . 4 37.384617  40.22727 2
    "BOL" 111 "apt"                    . "LAC"  5 . . 4 37.384617  40.22727 1
    "BHS" 131 "singh"                  . "LAC" 65 . . 4 37.384617  40.22727 3
    "BOL" 131 "singh"                  . "LAC" 22 . . 4 37.384617  40.22727 3
    "BHS" 111 "apt"                    . "LAC" 58 . . 4 37.384617  40.22727 1
    "URY" 111 "apt"                    . "LAC" 10 . . 4 37.384617  40.22727 1
    "MSR" 111 "apt"                    . "LAC" 72 . . 4 37.384617  40.22727 1
    "JAM" 131 "singh"                  . "LAC" 32 . . 4 37.384617  40.22727 3
    "PAN" 131 "singh"                  . "LAC" 61 . . 4 37.384617  40.22727 3
    end
    label values loc_two loc_two_1
    label def loc_two_1 1 "high", modify
    label def loc_two_1 2 "low", modify
    label values loc_three loc_three_1
    label def loc_three_1 1 "high_r", modify
    label def loc_three_1 2 "low_r", modify
    label def loc_three_1 3 "med_r", modify
    label values reg_no reg_no
    label def reg_no 1 "AFR", modify
    label def reg_no 2 "ASS", modify
    label def reg_no 3 "EUR", modify
    label def reg_no 4 "LAC", modify
    label values iname_no iname_no
    label def iname_no 1 "apt", modify
    label def iname_no 2 "rowh", modify
    label def iname_no 3 "singh", modify

  • #2
    Any of the standard output routines (many have been mentioned on this list-serve, search for Word or Excel), will do the first part of what you want. The means are not standard so you may need to calculate them (maybe with table or one of the table routines) and then cut and paste them into tables.

    Comment


    • #3
      Indeed, I faced the issue that you just raised. Maybe there is a way to access the estimates stored in Stata's 'table' command (which I would use to generate) means. This would help.

      Apartfrom that I have looked into the following approaches with no luck:

      -'statby' doesn't work because I am not running the same regression across groups. I am running different regressions over the same data.
      -'rangestat' package doesn't help either. Don't understand it too well, but I immediately faced a road block when running a regression with it, since factor-variable operators are not allowed.

      Comment


      • #4
        I am not sure what are you going to do with the regression estimates stored in the Stata memory. However, if you are comfortable with the output in MS Word, then asdoc can create a table closer to what you have specificed above

        Code:
        ssc install asdoc
        asdoc reg logvalue loc_two ib2.reg_no ib2.iname_no, baselevels nest replace cnames(Model1)  abb label
        
        di "model2"
        asdoc reg logvalue ib2.reg_no#ib1.loc_three ib2.iname_no, baselevels nest cnames(Model2)  abb(.) label
        
        
        di "model3"
        asdoc reg logvalue ib2.reg_no#ib1.loc_three ib2.iname_no, baselevels nest cnames(Model3)  abb(.) label
        More on asdoc can be found here https://fintechprofessor.com/2018/01/31/asdoc/
        Regards
        --------------------------------------------------
        Attaullah Shah, PhD.
        Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
        FinTechProfessor.com
        https://asdocx.com
        Check out my asdoc program, which sends outputs to MS Word.
        For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

        Comment


        • #5
          Hi Attaullah. Your suggestion creates a publication-type table. It looks nice but it is not what I am after. Thanks in any case!

          Comment

          Working...
          X