Xi asked the following quesiton:

**How can I get p-values and t-values using asreg program?**

## Introduction to asreg

asreg is a Stata program, written by Dr. Attaullah Shah. The program is available for free and can be downloaded from SSC by typing the following on the Stata command window:

ssc install asreg

asreg was primarily written for rolling/moving / sliding window regressions. However, with the passage of time, several useful ideas were conceived by its creator and users. Therefore, more features were added to this program.

## Getting t-values after asreg

Consider the following example where we use the * invest *and independent variables are

*mvalue*and

*kstock*. Let’s estimate the regression model separately for each company, denoted by

i In the following lines of code, the letters * se* after comma causes asreg to report the standard errors for each regression coefficient.

webuse grunfeld, clear

tsset

bys company: asreg invest mvalue kstock, se

asreg generates the regression coefficients, r-squared, adjusted r-squared, number of observations (_Nobs) and standard errors for each coefficient. This is enough information for producing t-values and p-values for the regression coefficients. The t-values can be generated by:

gen t_values_Cons = _b_cons / _se_cons

gen t_values_mvalue = _b_mvalue / _se_mvalue

gen t_values_kstock = _b_kstock / _se_kstock

## Getting p-values after asreg

Getting p-values is just one step away. We need one additional bit of information from the regression estimates, that is the *degrees of freedom*. This is usually equal to the number of observations minus the number of parameters being estimated. Since we have two independent variables and one constant, the number of parameters being estimated are 3. asreg returns the number of observation in the variable ** _Nobs**. Therefore, the term

**in the following lines of code is a way to get the**

*_Nobs – 3**degrees of freedom.*

gen p_values_Cons = (2 * ttail(_Nobs-3), abs( _b_cons / _se_cons ))

gen p_values_mvalue = (2 * ttail(_Nobs-3), abs( _b_mvalue / _se_mvalue ))

gen p_values_kstock = (2 * ttail(_Nobs-3), abs( _b_kstock / _se_kstock ))

### Verify the Results

Let’s estimate a regression for the first company and compare our estimates with those produced by the Stata regress command.

reg invest mvalue kstock if company == 1

list _b_cons _se_cons p_values_Cons in 1

### Full Code

webuse grunfeld, clear

tsset

bys company: asreg invest mvalue kstock, se

gen t_values_Cons = _b_cons / _se_cons

gen t_values_mvalue = _b_mvalue / _se_mvalue

gen t_values_kstock = _b_kstock / _se_kstock

gen p_values_Cons = (2 * ttail(_Nobs-3), abs( _b_cons / _se_cons ))

gen p_values_mvalue = (2 * ttail(_Nobs-3), abs( _b_mvalue / _se_mvalue ))

gen p_values_kstock = (2 * ttail(_Nobs-3), abs( _b_kstock / _se_kstock ))

reg invest mvalue kstock if company == 1

list _b_cons _se_cons t_values_Cons p_values_Cons in 1

XiFebruary 13, 2019 at 10:50 pmProblem solved!

AliOctober 21, 2019 at 8:52 pmhi,

while calculating p-value what does 2 represent? and also ttail?

(2 * ttail(_Nobs-3)

AliOctober 21, 2019 at 10:48 pmi think i got it, it two tailed t test?

Attaullah ShahOctober 21, 2019 at 11:22 pmYes, that is correct.

AndreaDecember 4, 2019 at 2:54 amHi prof.

first of all, thanks for your wonderful contribution.

Is there the possibility to have the F-test in the output? I mean, first of all, the P-value of the F-test.

Thanks in advance.

Andrea

Attaullah ShahDecember 4, 2019 at 4:19 pmAndrea

The F-statistics is currently not available. Thanks for the suggestion. I shall consider it in the next update.

LiApril 22, 2020 at 9:44 pmHi Attaullah,

I am using asreg to do Fama-MacBeth regression for two subsamples, and test whether the two reg coefficients are different. I first use “est store” to store the coefficients, and then use “suest” to compare them. However, STATA reported the error as “

“.

Is this because asreg is not compatible with

`suest?`

In this case, is there an easy way to compare the coefficients of asreg from different samples? Thank you!