Statalist


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

Re: st: inconsistent do-file execution PLUS


From   "Austin Nichols" <austinnichols@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: inconsistent do-file execution PLUS
Date   Sun, 8 Jun 2008 20:44:32 -0400

Rufus Peabody <rufus.peabody@gmail.com>:
-help sort- discusses this problem (and the -stable- option) at length.
As for Stata 9 going bonkers, sounds like a corrupt file or bad memory.
Did you try deleting Stata and re-installing?


On Sun, Jun 8, 2008 at 8:24 PM, Rufus Peabody <rufus.peabody@gmail.com> wrote:
> Friedrich (and others),
>
> I think I found the problem.  I didn't have an ID variable for a certain
> subsection of the data, but I'm still curious why the file would execute
> differently each time.  The problem was the commands:
>
>>> sort gameid
>>> gen runavg_opp_pred=runavg_tm_pred[_n-1] if gameid[_n-1]==gameid
>>> replace runavg_opp_pred=runavg_tm_pred[_n+1] if gameid[_n+1]==gameid
>
> I'm using a dataset with many observations from years 2001-2007.  The
> variable "gameid" was missing for all 2006 & 2007 observations.  Would the
> sort execute differently each time for observations where the sorting
> variable is missing?  That doesn't seem to make sense to me.
>
>
> Another question that's somewhat related:
>
> I just got Stata 10, but I had Stata 9 IC for Mac for the previous year and
> every so often Stata would go bonkers on me.  I would execute a simple
> command (like summarize) and it would give me different results each time.
>  Sometimes Stata would even change my dataset by deleting lots of
> observations and copying some rows hundreds of times.  Other times, it would
> make the dataset look like nonsense (it would be filled with characters such
> as ~ˆøå¬πøˆ¨(c).  When I quit Stata and restarted it, everything would be back
> to normal.  I should note that Stata would usually only mess up like this
> after I had been using it for awhile--it would never do this right after I
> launched it.  Would have written about this problem earlier, but just found
> out about the listserv.
>
> Thanks again,
>
> Rufus
>
>
>
> On Jun 8, 2008, at 7:54 PM, Friedrich Huebler wrote:
>
>> Rufus,
>>
>> At which step do you get different results? Please provide a more
>> precise description of your problem.
>>
>> Thanks,
>>
>> Friedrich
>>
>> On Sun, Jun 8, 2008 at 7:48 PM, Rufus Peabody <rufus.peabody@gmail.com>
>> wrote:
>>>
>>> Hey all,
>>>
>>> I'm using Stata 10 SE for Mac.  I'm having a problem with the execution
>>> of a
>>> do-file--each time I do the do-file, I get different results for only a
>>> subset of the data.  First of all, is there any reason why running the
>>> same
>>> do-file which is using the exact same data would give me different
>>> results?
>>> The do-file is a bit long but I'll paste it in here, although I'm not
>>> sure
>>> how it would give me different results since I'm not simulating
>>> anything...
>>>
>>> Thanks,
>>> Rufus
>>>
>>>
>>> use iteration2a_lag_bet.dta
>>>
>>>
>>> regress kpct lkpct_norm_pit_003 lkpct_norm_opp_01 ltotal_bf
>>> lp_pa_norm_pit_up003 lstrike_pct_norm_opp_up01 lbip_pct_norm_opp_up01
>>> kpct_int_bf if year<2005 & home==1
>>> predict kpct_pred_home if home==1
>>> regress kpct lkpct_norm_pit_003 lkpct_norm_opp_01 ltotal_bf
>>> lp_pa_norm_pit_up003  lbip_pct_norm_opp_up01 kpct_int_bf if year<2005 &
>>> home==0
>>> predict kpct_pred_away if home==0
>>>
>>> regress bbpct ltotal_bf lbbpct_norm_pit_003 lbbpct_norm_opp_up01
>>> bbpct_int_bf lp_pa_norm_pit_up003 lp_pa_norm_opp_up01
>>> lstrike_pct_norm_opp_up01 lstrike_pct_norm_pit_up003 lhrpct_norm_opp_up01
>>> if
>>> year<2005 & home==1
>>> predict bbpct_pred_home if home==1
>>> regress bbpct ltotal_bf lbbpct_norm_pit_003 lbbpct_norm_opp_up01
>>> bbpct_int_bf lp_pa_norm_pit_up003 lp_pa_norm_opp_up01
>>> lstrike_pct_norm_opp_up01 lstrike_pct_norm_pit_up003 if year<2005 &
>>> home==0
>>> predict bbpct_pred_away if home==0
>>>
>>> regress hrpct ltotal_bf hr_bip_pfbf ladjhrpct_norm_pit_up003
>>> ladjhrpct_norm_opp_up01 lebh_bip_norm_opp_up01 lebh_bip_norm_pit_up003
>>> lbip_pct_norm_pit_up003 lgdppct_norm_pit_up003 if year<2005 & home==1
>>> predict hrpct_pred_home if home==1
>>> regress hrpct ltotal_bf hr_bip_pfbf ladjhrpct_norm_pit_up003
>>> ladjhrpct_norm_opp_up01 lebh_bip_norm_pit_003 lbip_pct_norm_pit_up003
>>> lgdppct_norm_pit_up003 lgdppct_norm_opp_01 if year<2005 & home==0
>>> predict hrpct_pred_away if home==0
>>>
>>> regress babip babip_pfbf ltotal_bf lbabip_norm_pit_003 lbabip_norm_opp
>>> lbip_pct_norm_pit_up003 if home==1 & year<2005
>>> predict babip_pred_home if home==1
>>> regress babip babip_pfbf ltotal_bf lbabip_norm_pit_003 lbabip_norm_opp_up
>>> lbip_pct_norm_pit_up003 if home==0 & year<2005
>>> predict babip_pred_away if home==0
>>>
>>> regress woba woba_pfbf kpct_pred_home bbpct_pred_home hrpct_pred_home
>>> babip_pred_home if home==1 & year<2005, robust
>>> predict woba_pred_home if home==1
>>> regress woba woba_pfbf kpct_pred_away bbpct_pred_away hrpct_pred_away
>>> babip_pred_away if home==0 & year<2005, robust
>>> predict woba_pred_away if home==0
>>>
>>> regress ip lip_norm_pit_up003 ltotal_bf woba_pred_home bbpct_pred_home if
>>> year<2005 & home==1, robust
>>> predict ip_pred_home if home==1
>>> regress ip lip_norm_pit_up003 ltotal_bf woba_pred_away if year<2005 &
>>> home==0, robust
>>> predict ip_pred_away if home==0
>>>
>>> regress bip_pct lbip_pct_norm_pit_up003 lkpct_norm_opp_up01
>>> lbbpct_norm_opp_up01   if year<2005 & home==1, robust
>>> predict bip_pct_pred_home if home==1
>>> regress bip_pct lbip_pct_norm_pit_up003 lkpct_norm_opp_up01
>>> lbbpct_norm_opp_up01   if year<2005 & home==0, robust
>>> predict bip_pct_pred_away if home==0
>>>
>>>
>>> regress kpct_pen lkpct_norm_pen_up01 lkpct_norm_opp_up01
>>> lbip_pct_norm_opp_up01 ip_pred_home pitchers_lastweek_pen if year<2005 &
>>> home==1, robust
>>> predict kpct_pen_pred_home if home==1
>>> regress kpct_pen lkpct_norm_pen_01 lkpct_norm_opp_01
>>> lbip_pct_norm_opp_up01
>>> lbip_pct_norm_pen_01 lstrike_pct_norm_pen_01 pitchers_lastweek_pen
>>> ip_pred_away if year<2005 & home==0, robust
>>> predict kpct_pen_pred_away if home==0
>>>
>>> regress bbpct_pen lbbpct_norm_pen_01  lbbpct_norm_opp_01
>>> lstrike_pct_norm_pen_01 pitchers_lastweek_pen if year<2005 & home==1,
>>> robust
>>> predict bbpct_pen_pred_home if home==1
>>> regress bbpct_pen  lbbpct_norm_opp_01 lstrike_pct_norm_pen_01
>>> pitchers_lastweek_pen if year<2005 & home==0, robust
>>> predict bbpct_pen_pred_away if home==0
>>>
>>> regress babip_pen babip_pfbf lbabip_norm_pen_01  ip_pred_home
>>> ip_lastweek_pen if year<2005 & home==1, robust
>>> predict babip_pen_pred_home if home==1
>>> regress babip_pen babip_pfbf lbabip_norm_pen_01  ip_pred_away
>>> pitchers_lastweek_pen if year<2005 & home==0, robust
>>> predict babip_pen_pred_away if home==0
>>>
>>> regress hrpct_pen hrpct_pfbf ladjhrpct_norm_opp_01 ladjhrpct_norm_pen_01
>>> ip_pred_home ip_lastweek_pen  if year<2005 & home==1
>>> predict hrpct_pen_pred_home if home==1
>>> regress hrpct_pen hrpct_pfbf ladjhrpct_norm_opp_01 ladjhrpct_norm_pen_01
>>>  if
>>> year<2005 & home==0
>>> predict hrpct_pen_pred_away if home==0
>>>
>>> regress woba_pen kpct_pen_pred_home bbpct_pen_pred_home
>>> babip_pen_pred_home
>>> hrpct_pen_pred_home if year<2005 & home==1, robust
>>> predict woba_pen_pred_home if home==1
>>> regress woba_pen kpct_pen_pred_away bbpct_pen_pred_away
>>> babip_pen_pred_away
>>> hrpct_pen_pred_away if year<2005 & home==0, robust
>>> predict woba_pen_pred_away if home==0
>>>
>>>
>>> regress runavg_pen woba_pen_pred_home if year<2005 & home==1, robust
>>> predict runavg_pen_pred_home if home==1
>>> regress runavg_pen woba_pen_pred_away if year<2005 & home==0, robust
>>> predict runavg_pen_pred_away if home==0
>>>
>>>
>>> regress runavg woba_pred_home if year<2005 & home==1, robust
>>> predict runavg_pred_home if home==1
>>> regress runavg woba_pred_away if year<2005 & home==0, robust
>>> predict runavg_pred_away if home==0
>>>
>>> gen runavg_pred_home_IP=runavg_pred_home*ip_pred_home
>>> gen runavg_pred_away_IP=runavg_pred_away*ip_pred_away
>>>
>>> regress runavg_tm runavg_pen_pred_home runavg_pred_home
>>> runavg_pred_home_IP
>>> if year<2005 & home==1, robust beta
>>> predict runavg_tm_pred_home if home==1
>>> regress runavg_tm runavg_pen_pred_away runavg_pred_away
>>> runavg_pred_away_IP
>>> if year<2005 & home==0, robust beta
>>> predict runavg_tm_pred_away if home==0
>>>
>>> gen runavg_tm_pred=runavg_tm_pred_home if home==1
>>> replace runavg_tm_pred=runavg_tm_pred_away if home==0
>>>
>>> sort gameid
>>> gen runavg_opp_pred=runavg_tm_pred[_n-1] if gameid[_n-1]==gameid
>>> replace runavg_opp_pred=runavg_tm_pred[_n+1] if gameid[_n+1]==gameid
>>>
>>> logit tm_win runavg_opp_pred runavg_tm_pred if home==1 & year<2005,
>>> robust
>>> predict home_win_new2 if home==1
>>>
>>>
>>> gen away_win_new2=1-home_win_new2
>>>
>>> gen strat1_ols_in_new2=tm_unit if home==1 & home_win_new2>tm_perc &
>>> home_win_new2~=. & year<2005
>>> gen strat1_ols_out_new2=tm_unit if home==1 & home_win_new2>tm_perc &
>>> home_win_new2~=. & year>2004
>>> replace strat1_ols_in_new2=opp_unit if home==1 & away_win_new2>opp_perc &
>>> home_win_new2~=. & year<2005
>>> replace strat1_ols_out_new2=opp_unit if home==1 & away_win_new2>opp_perc
>>> &
>>> home_win_new2~=. & year>2004
>>>
>>>
>>> regress tm_unit home_win_new2 tm_perc if home==1 & home_win_new2~=. &
>>> year<2005
>>> predict exp_return_home_new2 if home_win_new2!=.
>>> regress opp_unit home_win_new2 tm_perc if home==1 & home_win_new2~=. &
>>> year<2005
>>> predict exp_return_away_new2 if home_win_new2!=.
>>>
>>> ***
>>> gen strat2_ols_in_new2=opp_unit if exp_return_away_new2>0 &
>>> away_win_new2>opp_perc & year<=2004 & home_win_new2~=. & home==1 &
>>> exp_return_away_new2!=.
>>> replace strat2_ols_in_new2=tm_unit if exp_return_home_new2>0 &
>>> home_win_new2>tm_perc & year<=2004 & home_win_new2~=. & home==1 &
>>> exp_return_home_new2!=.
>>> gen strat2_ols_out_new2=opp_unit if exp_return_away_new2>0 &
>>> away_win_new2>opp_perc & year>2004 & home_win_new2~=. & home==1 &
>>> exp_return_away_new2!=.
>>> replace strat2_ols_out_new2=tm_unit if exp_return_home_new2>0 &
>>> home_win_new2>tm_perc & year>2004 & home_win_new2~=. & home==1 &
>>> exp_return_home_new2!=.
>>>
>>>
>>> bysort year: summ strat2_ols_in strat2_ols_out strat1_ols_in
>>> strat1_ols_out
>>> [iweight=abs(home_win_new2-tm_perc)]*
>>
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/support/faqs/res/findit.html
>> *   http://www.stata.com/support/statalist/faq
>> *   http://www.ats.ucla.edu/stat/stata/
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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