Announcement

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

  • predict or margins with SSC gtools

    I am exploring and new with gtools SSC. I understand that is a beta version. I was surprised how fast is it.

    Specifically I am using logit regression but I wonder if exist some way to use predict or marginal means, I use this example:

    Code:
    ssc install gtools
    
    sysuse auto, clear
    expand 20000
    
    gglm foreign mpg price,  family(binomial)
    mata GtoolsLogit.print()
    
    predict pr
    last estimates not found
    Last edited by Rodrigo Badilla; 02 Apr 2026, 06:56.

  • #2
    I'm not sure it's prudent to be using the beta features in gtools in production code if you're not very familiar, and gglm in particular is even more complex than, say, greg (not to mention you should be using the github version, more so for the beta features). gglm is not super user friendly precisely because it is in beta: It doesn't modify values in e(), it doesn't give a coef table, etc.

    While it is possible to get a prediction, it involves some manual work; there's nothing as easy as predict pr, pr. So I think that the beta features are really only intended as that: beta for people who are already familiar with how gtools works.

    Comment


    • #3
      Thanks Mauricio,

      Yep I agree, I did mention about beta features, anyway here you can compare coefficients and the speed: 4 seconds with gglm vs 32 seconds with gml, not bad for a beta version.

      Unfortunately, it is incomplete version not too much options for post regression.

      Code:
      webuse lbw, clear
      expand 20000
      (3,779,811 observations created)
      
      timer clear 1        
      timer on 1  
      gglm low age lwt smoke ptl ht ui,  family(binomial)
      mata GtoolsLogit.print()
      
              -.0422544 ( .0002173)
              -.0142885 ( .0000512)
                .550631 ( .0024395)
                .593255 ( .0030955)
                1.86249 ( .0049629)
                 .73679 ( .0035342)
                1.37896 ( .0078052)
      timer off 1          
      timer list 1
         1:      4.00 /        1 =       4.0040
      
      timer clear 2      
      timer on 2
      glm low age lwt smoke ptl ht ui,  family(binomial)
      
      
      ------------------------------------------------------------------------------
                   |                 OIM
               low | Coefficient  std. err.      z    P>|z|     [95% conf. interval]
      -------------+----------------------------------------------------------------
               age |  -.0422544   .0002445  -172.79   0.000    -.0427337   -.0417751
               lwt |  -.0142885    .000047  -303.76   0.000    -.0143807   -.0141963
             smoke |   .5506312   .0024298   226.61   0.000     .5458689    .5553936
               ptl |   .5932548   .0024637   240.80   0.000      .588426    .5980835
                ht |   1.862491   .0048524   383.83   0.000      1.85298    1.872001
                ui |   .7367904   .0032279   228.26   0.000     .7304639    .7431169
             _cons |    1.37896   .0076996   179.09   0.000     1.363869    1.394051
      ------------------------------------------------------------------------------
      
      
      timer off 2        
      timer list 2
         2:     32.30 /        1 =      32.3050
      Last edited by Rodrigo Badilla; 03 Apr 2026, 08:31.

      Comment


      • #4
        Thanks. Like I mentioned, the github version should help getting a prediction that you can manipulate, but it's still a limited functionality. I haven't really had the chance to update gtools in a few years now, so keep that in mind as well when you consider relying on beta features.

        Comment

        Working...
        X