Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.

# Re: AW: st: AW: Simulate stepwise: Report coefficients from each replication

 From John Antonakis To statalist@hsphsun2.harvard.edu Subject Re: AW: st: AW: Simulate stepwise: Report coefficients from each replication Date Mon, 29 Mar 2010 18:12:16 +0200

```
```
In fact, Martin, I found a "trick" (ignore my lousy code for the groupings for the time being--I will update it).
```
```
So, Stata does "kick-out" coefficients that are not common. For instance, in the code I gave you before, it only identifies 5 betas from the simulation.
```
. fsum,

```
Variable N Mean SD Min Max _b_x1 11 1.72 0.57 1.02 2.81 _b_x2 9 1.77 1.30 -1.05 3.76 _b_x7 17 1.35 0.40 0.76 2.38 _b_x9 17 1.11 0.27 0.66 1.54 _b_x5 13 1.22 0.37 0.84 2.14 _b_cons 20 4.56 1.94 0.82 8.19 _se_x1 11 0.78 0.11 0.58 0.98 _se_x2 9 0.76 0.14 0.55 1.01 _se_x7 17 0.41 0.04 0.36 0.49 _se_x9 17 0.47 0.07 0.32 0.60 _se_x5 13 0.46 0.07 0.36 0.59 _se_cons 20 0.92 0.26 0.55 1.47
```
```
However, I used -outreg2- to post the results of each simulation, and voilà, problem solved! See new code below.
```
Best,
J.

clear
capture program drop sim
version 10.1
program define sim, eclass
drop _all

set obs 272
gen x1=rnormal()
gen x2=rnormal() +.2*x1
gen x3=rnormal() +.3*x1 + .3*x2
gen x4=rnormal() +.2*x1
gen x5=rnormal()
gen x6=rnormal() + .2*x5
gen x7=rnormal() + .5*x5
gen x8=rnormal() + .1*x7
gen x9=rnormal() + .1*x7

generate double e  = 5*rnormal()
generate double u  = sqrt(exp(-2+0.6*x1))*e

gen y = 5+ x1+x2+x3+x4+x5+x6+x7+x8+x9 + 2*u

reg y x*

sort x1
gen x1_count=_n
gen x1_high=1 if _n > 177
replace x1_high=0 if _n <178
gen x1_low=1 if _n < 96
replace x1_low=0 if _n>95

sort x2
gen x2_count=_n
gen x2_high=1 if _n > 177
replace x2_high=0 if _n <178
gen x2_low=1 if _n < 96
replace x2_low=0 if _n>95

gen group="high_high" if x1_high==1 & x2_high==1
replace group="low_low" if x1_low==1 & x2_low==1
replace group="low_high" if x1_low==1 & x2_high==1
replace group="high_low" if x1_high==1 & x2_low==1

stepwise, pr(.2): reg y x1-x9 if group=="low_low"
```
outreg2 using low_low2, tstat parenthesis(tstat) tdec(2) rdec(2) bdec(2) excel
```
end

simulate _b _se, reps(20) seed (123) : sim,

____________________________________________________

Prof. John Antonakis, Associate Dean
Department of Organizational Behavior
University of Lausanne
Internef #618
CH-1015 Lausanne-Dorigny
Switzerland

Tel ++41 (0)21 692-3438
Fax ++41 (0)21 692-3305

Faculty page:
http://www.hec.unil.ch/people/jantonakis

Personal page:
http://www.hec.unil.ch/jantonakis
____________________________________________________

On 29.03.2010 17:31, Martin Weiss wrote:
> <>
>
>
> What is your complaint, BTW? You get a red cross marker from -simulate-
> whenever one of the coefficients was dropped by -stepwise-. Which makes
> sense to me.
>
> What is " x1_count" and sister variable good for in your -program-?
>
>
> The high/low variables can be created as one-liners:
>
> *************
> gen byte x1_high= _n > 177
> *************
>
```
> Have you thought about the interaction between the two -seed-s that you set?
```>
>
> HTH
> Martin
>
>
> -----Ursprüngliche Nachricht-----
> Von: owner-statalist@hsphsun2.harvard.edu
```
> [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von John Antonakis
```> Gesendet: Montag, 29. März 2010 17:07
> An: statalist@hsphsun2.harvard.edu
> Betreff: Re: st: AW: Simulate stepwise: Report coefficients from each
> replication
>
> Sorry....I took bits out of some older code....in fact, the program is
> the following (where I want to show that stepwise gives nonsense
> findings, particularly when analyzing data within extreme
> groups--believe me, people do this and I am commenting on a paper that
> just did it)--I will run the below four times for each group (though
> with a bit of programming I guess it is possible to run it one):
>
> clear
> set seed 51
>
> capture program drop sim
>  version 10.1
> program define sim, eclass
>         drop _all
>
> set obs 272
> gen x1=rnormal()
> gen x2=rnormal() +.2*x1
> gen x3=rnormal() +.3*x1 + .3*x2
> gen x4=rnormal() +.2*x1
> gen x5=rnormal()
> gen x6=rnormal() + .2*x5
> gen x7=rnormal() + .5*x5
> gen x8=rnormal() + .1*x7
> gen x9=rnormal() + .1*x7
>
> generate double e  = 5*rnormal()
> generate double u  = sqrt(exp(-2+0.6*x1))*e
>
> gen y = 5+ x1+x2+x3+x4+x5+x6+x7+x8+x9 + 2*u
>
> reg y x*
>
> sort x1
> gen x1_count=_n
> gen x1_high=1 if _n > 177
> replace x1_high=0 if _n <178
> gen x1_low=1 if _n < 96
> replace x1_low=0 if _n>95
>
> sort x2
> gen x2_count=_n
> gen x2_high=1 if _n > 177
> replace x2_high=0 if _n <178
> gen x2_low=1 if _n < 96
> replace x2_low=0 if _n>95
>
> gen group="high_high" if x1_high==1 & x2_high==1
> replace group="low_low" if x1_low==1 & x2_low==1
> replace group="low_high" if x1_low==1 & x2_high==1
> replace group="high_low" if x1_high==1 & x2_low==1
>
> stepwise, pr(.2): reg y x1-x9 if group=="low_low"
>
> end
>
> simulate _b _se, reps(20) seed (123) : sim,
>
> Best,
> J.
>
> ____________________________________________________
>
> Prof. John Antonakis, Associate Dean
> Faculty of Business and Economics
> Department of Organizational Behavior
> University of Lausanne
> Internef #618
> CH-1015 Lausanne-Dorigny
> Switzerland
>
> Tel ++41 (0)21 692-3438
> Fax ++41 (0)21 692-3305
>
> Faculty page:
> http://www.hec.unil.ch/people/jantonakis
>
> Personal page:
> http://www.hec.unil.ch/jantonakis
> ____________________________________________________
>
>
>
> On 29.03.2010 17:02, Martin Weiss wrote:
>> <>
>>
>>
```
>> Where exactly do you define -program- "sim"? -simulate- expects a command
```>> after the colon, remember...
>>
>>
>>
>> HTH
>> Martin
>>
>>
>> -----Ursprüngliche Nachricht-----
>> Von: owner-statalist@hsphsun2.harvard.edu
>> [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von John
> Antonakis
>> Gesendet: Montag, 29. März 2010 16:56
>> An: statalist@hsphsun2.harvard.edu
```
>> Betreff: st: Simulate stepwise: Report coefficients from each replication
```>>
```
>> I want to highlight the evils of stepwise analysis. However, I am having
```>> problems in getting Stata to report the coefficients from each
>> replication --it seems that it only reports the coefficients that are
>> common across replications.  Anyone have any ideas?
>>
>> clear
>> set seed 51
>>
>> drop _all
>>
>> set obs 272
>> gen x1=rnormal()
>> gen x2=rnormal() +.2*x1
>> gen x3=rnormal() +.3*x1 + .3*x2
>> gen x4=rnormal() +.2*x1
>> gen x5=rnormal()
>> gen x6=rnormal() + .2*x5
>> gen x7=rnormal() + .5*x5
>> gen x8=rnormal() + .1*x7
>> gen x9=rnormal() + .1*x7
>>
>> generate double e  = 5*rnormal()
>> generate double u  = sqrt(exp(-2+0.6*x1))*e
>>
>> gen y = 5+ x1+x2+x3+x4+x5+x6+x7+x8+x9 + 2*u
>>
>> stepwise, pr(.2): reg y x1-x9
>>
>> end
>>
>> simulate _b _se, reps(20) seed (123) : sim,
>>
```
>> > *
```> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```