Hi All,

I am writing my Bachelor thesis which is about how total payout policy (dividends + share repurchases) is affected during a crisis period. Sample includes all firms in the economy excluding some based on their SIC codes (utilities & financial companies) and goes from 2000-2022.

I am trying to recreate one of the dependent variables the authors use in the paper I am using to inspire my topic. They generate a binary variable which is equal to 1 if the total payout decreases 5% or more from the previous two-year average payout, zero otherwise.


My data is quarterly and I am struggling to find the correct coding that would create a variable which would indicate, at each observation, the average of the last 8 quarters for total payout.

How part of the data looks (in the 2005-2009 period):

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float TotalPayout double FiscalY str70 Company  2.38716 2005 "ALPHARMA INC  -CL A"         
 2.397735 2005 "ALPHARMA INC  -CL A"         
   2.4057 2005 "ALPHARMA INC  -CL A"         
  2.43351 2005 "ALPHARMA INC  -CL A"         
  2.46069 2006 "ALPHARMA INC  -CL A"         
 2.465415 2006 "ALPHARMA INC  -CL A"         
  2.46789 2006 "ALPHARMA INC  -CL A"         
 309.3365 2006 "ALPHARMA INC  -CL A"         
13.674925 2005 "AVX CORP"                    
13.687975 2005 "AVX CORP"                    
 19.54405 2005 "AVX CORP"                    
  22.2461 2005 "AVX CORP"                    
 8.829125 2006 "AVX CORP"                    
  13.9802 2006 "AVX CORP"                    
 17.35915 2006 "AVX CORP"                    
21.244776 2006 "AVX CORP"                    
  6.87604 2007 "AVX CORP"                    
 13.39452 2007 "AVX CORP"                    
 21.10808 2007 "AVX CORP"                    
 23.98364 2007 "AVX CORP"                    
 10.22676 2008 "AVX CORP"                    
 13.95108 2008 "AVX CORP"                    
  16.3456 2008 "AVX CORP"                    
 18.23736 2008 "AVX CORP"                    
  7.43484 2009 "AVX CORP"                    
 8.303761 2009 "AVX CORP"                    
 8.303761 2009 "AVX CORP"                    
 10.53896 2009 "AVX CORP"                    
  928.606 2005 "ABBOTT LABORATORIES"         
 839.8484 2005 "ABBOTT LABORATORIES"         
1016.0547 2005 "ABBOTT LABORATORIES"         
1725.6036 2005 "ABBOTT LABORATORIES"         
1174.2117 2006 "ABBOTT LABORATORIES"         
1205.2051 2006 "ABBOTT LABORATORIES"         
1207.2869 2006 "ABBOTT LABORATORIES"         
1207.9886 2006 "ABBOTT LABORATORIES"         
 1315.609 2007 "ABBOTT LABORATORIES"         
1365.7422 2007 "ABBOTT LABORATORIES"         
1560.8197 2007 "ABBOTT LABORATORIES"         
1562.5138 2007 "ABBOTT LABORATORIES"         
1320.7212 2008 "ABBOTT LABORATORIES"         
 1626.392 2008 "ABBOTT LABORATORIES"         
1631.6965 2008 "ABBOTT LABORATORIES"         
 1640.682 2008 "ABBOTT LABORATORIES"         
1379.3182 2009 "ABBOTT LABORATORIES"         
 1443.146 2009 "ABBOTT LABORATORIES"         
 1444.081 2009 "ABBOTT LABORATORIES"         
1446.8123 2009 "ABBOTT LABORATORIES"         
    .1284 2005 "SERVIDYNE INC"               
 .1173726 2005 "SERVIDYNE INC"               
  .127116 2005 "SERVIDYNE INC"               
  .127152 2005 "SERVIDYNE INC"               
  .127152 2006 "SERVIDYNE INC"               
  .145972 2006 "SERVIDYNE INC"               
  .146972 2006 "SERVIDYNE INC"               
  .127044 2007 "SERVIDYNE INC"               
   .12708 2007 "SERVIDYNE INC"               
   .12744 2007 "SERVIDYNE INC"               
   .12744 2007 "SERVIDYNE INC"               
 .1357257 2008 "SERVIDYNE INC"               
   .19955 2008 "SERVIDYNE INC"               
  .276296 2008 "SERVIDYNE INC"               
   .20984 2008 "SERVIDYNE INC"               
   .07382 2009 "SERVIDYNE INC"               
   .04189 2009 "SERVIDYNE INC"               
   .06776 2009 "SERVIDYNE INC"               
   .06776 2009 "SERVIDYNE INC"               
   1.8186 2005 "ACETO CORP"                  
  1.82115 2005 "ACETO CORP"                  
 2.400275 2006 "ACETO CORP"                  
  2.40185 2006 "ACETO CORP"                  
 1.824225 2007 "ACETO CORP"                  
    2.433 2007 "ACETO CORP"                  
  3.66525 2008 "ACETO CORP"                  
   2.4446 2008 "ACETO CORP"                  
   2.4766 2009 "ACETO CORP"                  
   2.4771 2009 "ACETO CORP"                  
  1.02526 2005 "ACME UNITED CORP"            
   2.2742 2005 "ACME UNITED CORP"            
  3.30588 2005 "ACME UNITED CORP"            
  3.66849 2005 "ACME UNITED CORP"            
   .10455 2006 "ACME UNITED CORP"            
   .10485 2006 "ACME UNITED CORP"            
   .10491 2006 "ACME UNITED CORP"            
   .10542 2006 "ACME UNITED CORP"            
   .45251 2007 "ACME UNITED CORP"            
   .48848 2007 "ACME UNITED CORP"            
   .62732 2007 "ACME UNITED CORP"            
   .63312 2007 "ACME UNITED CORP"            
    .9274 2008 "ACME UNITED CORP"            
   .92784 2008 "ACME UNITED CORP"            
   1.1402 2008 "ACME UNITED CORP"            
  2.64415 2008 "ACME UNITED CORP"            
   .38115 2009 "ACME UNITED CORP"            
    .3814 2009 "ACME UNITED CORP"            
   1.0309 2009 "ACME UNITED CORP"            
   1.8959 2009 "ACME UNITED CORP"            
    6.698 2007 "BK TECHNOLOGIES CORP"        
  1.56066 2005 "ADAMS RESOURCES & ENERGY INC"
  1.77156 2006 "ADAMS RESOURCES & ENERGY INC"
 end

I would want to have the following 2 year average for example:

TotalPayout double FiscalY str70 Company 2-year Average
13.674925 2005 "AVX CORP" No average
13.687975 2005 "AVX CORP" No average
19.54405 2005 "AVX CORP" No average
22.2461 2005 "AVX CORP" No average
8.829125 2006 "AVX CORP" No average
13.9802 2006 "AVX CORP" No average
17.35915 2006 "AVX CORP" No average
21.244776 2006 "AVX CORP" No average
6.87604 2007 "AVX CORP" Average of Q1 2005 - Q4 2006
13.39452 2007 "AVX CORP" Average Q2 2005 - Q1 2007
21.10808 2007 "AVX CORP" Average Q3 2005 - Q2 2007
23.98364 2007 "AVX CORP" Average Q4 2005 - Q3 2007
10.22676 2008 "AVX CORP" Average Q1 2006 - Q4 2007
13.95108 2008 "AVX CORP"
16.3456 2008 "AVX CORP"
18.23736 2008 "AVX CORP"
7.43484 2009 "AVX CORP"
8.303761 2009 "AVX CORP"
8.303761 2009 "AVX CORP"
10.53896 2009 "AVX CORP"


I am not sure if this is possible hence I am reaching out. I would be very grateful for any type of input.


Thank you,
Viktor Christian