## Getting p-values and t-values with asreg

Category:Blog,Stata ProgramsXi 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

## 6 Comments

## Xi

February 13, 2019at 10:50 pmProblem solved!

## Ali

October 21, 2019at 8:52 pmhi,

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

(2 * ttail(_Nobs-3)

## Ali

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

## Attaullah Shah

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

## Andrea

December 4, 2019at 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 Shah

December 4, 2019at 4:19 pmAndrea

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