Announcement

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

  • Store results, save coefficients, saving a single coefficient for multiple regressions

    Good morning everyone,

    I am currently running a set of regressions and would like to save and visualize only the coefficient for the "Female" variable for each region. Is there a way to do this efficiently?

    Thank you very much in advance for your help!

    Code:
    by region, sort: regr lnweeklyIncome Female  $worker_reg $inq_reg $contr_reg $firm_charact $territorial_charact_reg if  MYsampleREG == 1  [aweight=peso]

  • #2
    Code:
    ssc install estout
    ssc install coefplot
    Code:
    qui levelsof region, local(regions)
    eststo clear
    *ASSUMES REGION IS A NUMERIC VARIABLE
    foreach region of local regions{
        eststo: regr lnweeklyIncome Female $worker_reg $inq_reg $contr_reg $firm_charact $territorial_charact_reg if MYsampleREG == 1 & region==`region'  [aweight=peso]
    }
    coefplot est*, keep(Female)

    Comment


    • #3
      Dear Andrew Musau thank you so much for your suggestion,the command works perfectly.


      Could you explain the rules you follow when adding an "s" to "region"? Is it a name you created, or do you need to add an "s" to the original variable name?

      I’m still interested in understanding the logic behind it because I’d need to apply it in other estimates. Also, the graph is extremely useful—thank you for the suggestion! Could you also provide some advice on how to display the numerical values (without the graph) in a table or list format by region, etc.?

      Thank you so much for your help
      Last edited by Chiara Tasselli; 27 Aug 2024, 05:59.

      Comment


      • #4
        Originally posted by Chiara Tasselli View Post

        Could you explain the rules you follow when adding an "s" to "region"? Is it a name you created, or do you need to add an "s" to the original variable name?
        It's a name I created. You can name your local macro whatever you want. To me, it just seems natural to name the local holding the region names "regions." Additionally, how you denote the index is arbitrary, so you could have:

        Code:
        levelsof region, local(myname)
        foreach j of local myname{
            regress ... if region==`j' ...
        }
        Could you also provide some advice on how to display the numerical values (without the graph) in a table or list format by region, etc.?
        This can be done by merging the models from the stored results. However, it's easier to store these while executing the loop. Here is an example using the census dataset, where the coefficient of interest is that on marriage.

        Code:
        cap frame change default
        sysuse census, clear
        levelsof region, local(regions)
        estimates clear
        cap frame drop results
        frame create results str100 region float(b se t pvalue ll ul)
        foreach region of local regions{
            eststo: regress pop marriage medage if region==`region', robust
            frame post results ("`:lab (region) `region''") (r(table)["b", "marriage"]) ///
                               (r(table)["se", "marriage"]) (r(table)["t", "marriage"]) ///
                               (r(table)["pvalue", "marriage"]) (r(table)["ll", "marriage"]) ///
                               (r(table)["ul", "marriage"])
        }
        frame change results
        list, sep(0)
        Res.:

        Code:
        . frame change results
        
        . list, sep(0)
        
             +---------------------------------------------------------------------------+
             |  region          b         se          t     pvalue         ll         ul |
             |---------------------------------------------------------------------------|
          1. |      NE    122.145   2.454866   49.75629   4.42e-09   116.1382   128.1519 |
          2. | N Cntrl   106.9078   2.228242   47.97853   3.72e-12   101.8672   111.9484 |
          3. |   South   76.58729   1.407905   54.39806   1.01e-16   73.54569   79.62888 |
          4. |    West   98.33881   26.65503   3.689316   .0041816    38.9477   157.7299 |
             +---------------------------------------------------------------------------+
        Last edited by Andrew Musau; 27 Aug 2024, 09:16.

        Comment


        • #5
          Andrew Musau Once again, many thanks! You have helped me so much, and your advice has been very helpful.

          Comment

          Working...
          X