Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7930125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:19:09+00:00 2026-06-03T20:19:09+00:00

In Stata, after a regression I know it is possible to call the elements

  • 0

In Stata, after a regression I know it is possible to call the elements of stored results by name. For example, if I want to manipulate the coefficient on the variable precip, I just type _b[precip]. My question is how do I do the same after the tabstat command? For example, say I want to multiply the coefficient on precip by the sample mean of precip:

    reg --variables in regression--
    tabstat --variables in regression--
    mat X=r(StatTotal)
    mat Y=_b[precip]*X[1,precip]

Ah, if only it were that simple. But alas, in the last line X[1, precip] is invalid syntax. Oddly, Stata does recognize display X[1, precip]. And Stata would know what I’m trying to do if instead of precip I used the column number where precip appears in the X vector. If I were just doing this operation once, no problem. But I need to do this operation several times (for several different model specifications) and for several variables which change position in the vector from one model to the next, so I cannot just use the column number.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T20:19:13+00:00Added an answer on June 3, 2026 at 8:19 pm

    I am not yet sure I understand exactly what you want to do, but here’s my attempt to reproduce what you are doing:

        sysuse auto, clear
        regress price mpg foreign weight
        tabstat mpg foreign weight, save
        matrix X = r(StatTotal)
        matrix Y = _b[mpg]*X[1, colnumb(X, "mpg") ]
    

    If you need to put this into a cycle, that’s doable, too:

        matrix bb = e(b)
        local explvar : colnames bb
        foreach x in `explvar' {
          if "`x'" != "_cons" {
            matrix Y_`x' = _b[`x'] * X[1, colnumb(X, "`x'")]
          }
          else {
            matrix Y_`x' = _b[`x']
          }
        }
    

    You’d probably want to put this into a program that you will call after each regression model estimation call, e.g.:

        program define reg2mat , prefix( name )
    
          if "`e(cmd)'" != "regress" {
            // this will intentionally produce an error
            regress
          }
    
          tempname bb
    
          matrix `bb' = e(b)
          local explvar : colnames `bb'
          foreach x in `explvar' {
            if "`x'" != "_cons" {
              matrix `prefix'_`x' = _b[`x'] * X[1, colnumb(X, "`x'")]
            }
            else {
              matrix `prefix'_`x' = _b[`x']
            }
          }
        end // of reg2mat
    

    At many levels, it is not ideal, as it manipulates with the (global) matrices in Stata memory; most of the time, it is a bad idea, as the programs should only manipulate with objects local to them.

    I suspect that what you want to do is addressed, in one way or another, by either omnipowerful margins command, or by an appropriate predict, or by matrix score (which is the low level version of predict). Attributing the effects to a variable only makes sense when your regressors are orthogonal, which only happens in carefully designed and conducted experiments.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to export a matrix of regression results from Stata to MATLAB. I
I want to ensure that a WCF-ServiceClient State will be closed after using the
1) Is it possible to create a vector of strings in stata? 2) If
I wish to detect the call state after my app resumes the active state
is it possible to reset to original state after changing class and applying the
How do you detect the current SCAN state and revert it after changing it?
We are using Stata to combine and analyze data for all of our agencies
I need some help with Stata. I'm not sure if this is the right
My aim is to restore an Oracle database back to it's previous state after
I am running a program in Go which sends data continuously after reading a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.