Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Variable dropped from regression: how to capture event?

From   "Michael S. Hanson" <>
Subject   Re: st: Variable dropped from regression: how to capture event?
Date   Sat, 18 Nov 2006 10:20:42 -0500

On Nov 18, 2006, at 5:46 AM, Maarten buis wrote:

One way to see if one or more variables are dropped is by counting the
number of rows in the e(b) matrix and compare it with the number of
variables + constant if no variable is dropped like in the example
I noticed two problems with Maarten's code below -- although in this particular case the "correct" answer would be returned. First, to count the number of variables in the varlist local macro, `varlist' needs to be quoted in the -local : word count- extended macro command. (Without the quotes, the answer will always be 1, so `allk' will always be 2.) Second, the number of regressors will be the number of columns of e(b), not rows. (In this case, e(b) is 1 x 4, so rowsof(b) = 1, whereas colsof(b) = 4).

Additionally, the use of the line-continuation comments /// is unnecessary here, and requires the code to be followed by a blank line. (Which I think is useful for improving readability, but is not strictly necessary.) In both cases, the standard // comment delimiter will work in the middle of a line.

Finally, I believe e(df_m) returns the number of (non-constant) regressors in the estimation. (Type -ereturn list- to see the statistics produced by -logit-.) So if I understand correctly, Maarten's example code could then be modified to be slightly more compact. I have made those three sets of changes to the code below:

//------------- begin example -------------
sysuse auto, clear
gen rep1 = rep78 <= 2
gen rep2 = rep78 == 3
gen rep3 = rep78 == 4
gen rep4 = rep78 == 5

// getting list of variables
local varlist "rep1 rep2 rep3 rep4"
local allk : word count `varlist'

logit foreign `varlist'

// see if a variable was dropped
di `allk'-e(df_m) // if > 0 a variable is dropped

// Alternative check for dropped variable
local allk = `allk' + 1 // add the constant
matrix b = e(b)
local k = colsof(b)
di `allk'-`k' // if > 0 a variable is dropped
//------------- end example -----------------

Hope this helps.

-- Mike

* For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index