Announcement

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

  • Displaying number of observations after "Repest" command

    I use the user written command "Repest" to analyse PISA survey data.
    I then use eststo and esttab to export the results to LaTeX.
    "Repest" stores the number of observation and r-squared as coefficients and not as statistic, so I have to use estadd to add them as a scalar.
    My problem is that when I use estadd I get an error message.


    The code I use is -
    Code:
    repest PISA, estimate(stata: reg pv@math female) /// results(add(N r2)) fast estadd scalar No = e_N estadd scalar r2 = e_r2 eststo m1 esttab m1
    When I run esttab I get
    Code:
    ----------------------------
                          (1)   
                                
    ----------------------------
    female             -13.62***
                     (-12.30)   
    
    _cons               456.4***
                     (411.44)   
    
    e_N                515956   
                          (.)   
    
    e_r2              0.00422***
                       (5.99)   
    ----------------------------
    N                           
    ----------------------------
    But the code gives an error message after the command
    Code:
    estadd scalar No = e_N
    The error message is:
    Code:
    "e_N not found"
    Could you help me extract these scalars (N and r2) after the "Repest" command?


    Stata/MP 15.1

  • #2
    Unfortunately, neither your post nor the documentation in the output of help repest shows a set of commands that would allow me to test my guess on actual data. With that said, perhaps your code should be
    Code:
    // the results option seems intented to instruct repest to retain
    // the e(N) and e(r2) from the regress command in the repest estimation results
    repest PISA, estimate(stata: reg pv@math female) ///
        results(add(N r2)) fast
    eststo m1
    esttab m1, r2

    Comment


    • #3
      Hi William, I have created a subsample of the data for you to test commands. What would be the best way to to share it with you?
      Stata/MP 15.1

      Comment


      • #4
        Did you first try my suggested code in post #2? I think the estadd commands are unnecessary. The results() option on the repest command should add e(N) and e(r2) from the regress command to the set of results that repest leaves in e(), After running the repest command, run the command ereturn list to see what is now in e().

        Comment


        • #5
          Yes I did. It did not work. When I run ereturn list after the repest command I get the following:
          end of do-file

          Code:
          . ereturn list
          
          scalars:
                            e(R) =  166.289
          
          macros:
                          e(cmd) : "."
                   e(properties) : "b V"
          
          matrices:
                            e(b) :  1 x 163
                            e(V) :  163 x 163
          (PS: How do you make a text in your reply appear as code in line, without it being surrounded in grey and moved to a new paragraph?)
          Stata/MP 15.1

          Comment


          • #6
            I think I was misled by the documentation provided in the help repast output. (Note: I made that look like code without being a code block by changing the font to Courier New using the Font dropdown in the "Advanced Editing" toolbar which if you don't see it, is revealed by clicking on the A in the middle of the three icons on the right in the posting window.)

            Your example in post #5, that the "estimates results" returned in e() is not where repest is saving the "results" specified the results() option. Or at least, they are not stored in separate scalars.

            If they are actually stored as coefficients, as you suggested, then they would be elements in the returned matrix e(b). Perhaps adapting the following example to your situation will help with your problem. If it does, I'm sorry for having initially set out on the wrong path.
            Code:
            . sysuse auto, clear
            (1978 Automobile Data)
            
            . quietly regress price length weight
            
            . matrix list e(b)
            
            e(b)[1,3]
                    length      weight       _cons
            y1  -97.960312   4.6990649   10386.541
            
            . matrix coeff = e(b)
            
            . // retrieve using row and column numbers
            . scalar b_n = coeff[1,2]
            
            . // retrieve using row and column names
            . scalar b_v = coeff[rownumb(coeff,"y1"),colnumb(coeff,"weight")]
            
            . display b_n " " b_v
            4.6990649 4.6990649
            Last edited by William Lisowski; 21 Dec 2019, 07:54.

            Comment


            • #7
              Thanks William,
              Your thorough answer has cleared everything. I can now extract the scalars and use them in my tables. It was great that you have bothered to provide the command for the column names, since I run 3 regressions each time, and the number of the relevant column changes each time (since each regression has more variables).
              Thanks a bunch!
              Stata/MP 15.1

              Comment


              • #8
                Dear William, I would like to kindly ask for your assistance again on a similar matter -

                mixed numscore1 lbe female books* immig* ,|| schoolid:

                and get the following output:

                Code:
                Performing EM optimization: 
                
                Performing gradient-based optimization: 
                
                Iteration 0:   log likelihood = -661767.19  
                Iteration 1:   log likelihood = -661767.19  
                
                Computing standard errors:
                
                Mixed-effects ML regression                     Number of obs     =    492,472
                Group variable: schoolid                        Number of groups  =      1,535
                
                                                                Obs per group:
                                                                              min =          1
                                                                              avg =      320.8
                                                                              max =      2,656
                
                                                                Wald chi2(11)     =   55475.89
                Log likelihood = -661767.19                     Prob > chi2       =     0.0000
                
                ------------------------------------------------------------------------------
                   numscore1 |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
                -------------+----------------------------------------------------------------
                         lbe |  -.1191841   .0028493   -41.83   0.000    -.1247686   -.1135997
                      female |  -.1540483   .0026483   -58.17   0.000    -.1592389   -.1488577
                      books1 |  -.8672732   .0061195  -141.72   0.000    -.8792671   -.8552792
                      books2 |  -.6698036   .0059917  -111.79   0.000     -.681547   -.6580601
                      books3 |  -.3961525    .005769   -68.67   0.000    -.4074596   -.3848455
                      books4 |  -.1850617   .0062339   -29.69   0.000      -.19728   -.1728434
                      books5 |   .0388173   .0065941     5.89   0.000     .0258932    .0517415
                      books6 |          0  (omitted)
                      immig1 |   .0275492   .0111689     2.47   0.014     .0056586    .0494397
                      immig2 |   .0598328   .0113963     5.25   0.000     .0374966    .0821691
                    immig_mo |  -.0616333   .0066826    -9.22   0.000     -.074731   -.0485356
                    immig_fa |  -.0567575   .0071256    -7.97   0.000    -.0707234   -.0427917
                       _cons |   .6041496   .0100567    60.07   0.000     .5844388    .6238603
                ------------------------------------------------------------------------------
                
                ------------------------------------------------------------------------------
                  Random-effects Parameters  |   Estimate   Std. Err.     [95% Conf. Interval]
                -----------------------------+------------------------------------------------
                schoolid: Identity           |
                                  var(_cons) |   .0952685   .0043435      .0871247    .1041735
                -----------------------------+------------------------------------------------
                               var(Residual) |   .8534137    .001723      .8500434    .8567974
                ------------------------------------------------------------------------------
                LR test vs. linear model: chibar2(01) = 8925.74       Prob >= chibar2 = 0.0000
                How do extract the details on the number of groups and the min/max number of observation in a group?
                Stata/MP 15.1

                Comment

                Working...
                X