#delimit ;

capture prog drop pellgrant;
program pellgrant;

/*
 Created by Drew M. Anderson and updated March 2020.
 Use, edit, share freely.
 Please contact me if there are errors: drew@rand.org.

 Example program call:

 gen mypell = .;
 pellgrant mypell ay efc;

 mypell (arg 1): numeric variable where Pell eligibility is to be stored
 ay     (arg 2): numeric aid year (e.g. 2009 for school year 2008-09)
 efc    (arg 3): numeric EFC

 mypell is coded as missing if ay is outside of 2008 through 2021.
 mypell is coded as missing if efc is missing.

 Source of payment schedules: ifap.ed.gov. See PDFs on the Code page of
  drewmanderson.com, where the original of this ado file can also be found.

 I use the full-time full-year grant eligibility on the bottom line of the
  Pell schedule, which applies to COA at or over max grant.

 Hardcoded (in order) grantstep=100, efcstep=100, minefc=0. ;
*/ ;

qui { ;
 gen maxgrant     = .;
 gen mingrant     = .;
 gen maxefc       = .;
 gen minstepgrant = .;
 gen maxstepefc   = .;

 replace maxgrant     = 4310 if `2'==2008;
 replace mingrant     =  400 if `2'==2008;
 replace maxefc       = 4110 if `2'==2008;
 replace minstepgrant =  460 if `2'==2008;
 replace maxstepefc   = 3900 if `2'==2008;

 replace maxgrant     = 4731 if `2'==2009;
 replace mingrant     =  890 if `2'==2009;
 replace maxefc       = 4041 if `2'==2009;
 replace minstepgrant =  981 if `2'==2009;
 replace maxstepefc   = 3800 if `2'==2009;

 replace maxgrant     = 5350 if `2'==2010;
 replace mingrant     =  976 if `2'==2010;
 replace maxefc       = 4617 if `2'==2010;
 replace minstepgrant = 1000 if `2'==2010;
 replace maxstepefc   = 4400 if `2'==2010;

 replace maxgrant     = 5550 if `2'==2011;
 replace mingrant     = 1176 if `2'==2011;
 replace maxefc       = 4617 if `2'==2011;
 replace minstepgrant = 1200 if `2'==2011;
 replace maxstepefc   = 4400 if `2'==2011;

 replace maxgrant     = 5550 if `2'==2012;
 replace mingrant     =  555 if `2'==2012;
 replace maxefc       = 5273 if `2'==2012;
 replace minstepgrant =  600 if `2'==2012;
 replace maxstepefc   = 5000 if `2'==2012;

 replace maxgrant     = 5550 if `2'==2013;
 replace mingrant     =  602 if `2'==2013;
 replace maxefc       = 4995 if `2'==2013;
 replace minstepgrant =  700 if `2'==2013;
 replace maxstepefc   = 4900 if `2'==2013;

 replace maxgrant     = 5645 if `2'==2014;
 replace mingrant     =  605 if `2'==2014;
 replace maxefc       = 5081 if `2'==2014;
 replace minstepgrant =  695 if `2'==2014;
 replace maxstepefc   = 5000 if `2'==2014;

 replace maxgrant     = 5730 if `2'==2015;
 replace mingrant     =  602 if `2'==2015;
 replace maxefc       = 5157 if `2'==2015;
 replace minstepgrant =  680 if `2'==2015;
 replace maxstepefc   = 5100 if `2'==2015;

 replace maxgrant     = 5775 if `2'==2016;
 replace mingrant     =  626 if `2'==2016;
 replace maxefc       = 5198 if `2'==2016;
 replace minstepgrant =  725 if `2'==2016;
 replace maxstepefc   = 5100 if `2'==2016;

 replace maxgrant     = 5815 if `2'==2017;
 replace mingrant     =  598 if `2'==2017;
 replace maxefc       = 5234 if `2'==2017;
 replace minstepgrant =  665 if `2'==2017;
 replace maxstepefc   = 5200 if `2'==2017;

 replace maxgrant     = 5920 if `2'==2018;
 replace mingrant     =  606 if `2'==2018;
 replace maxefc       = 5328 if `2'==2018;
 replace minstepgrant =  670 if `2'==2018;
 replace maxstepefc   = 5300 if `2'==2018;

 replace maxgrant     = 6095 if `2'==2019;
 replace mingrant     =  652 if `2'==2019;
 replace maxefc       = 5486 if `2'==2019;
 replace minstepgrant =  745 if `2'==2019;
 replace maxstepefc   = 5400 if `2'==2019;

 replace maxgrant     = 6195 if `2'==2020;
 replace mingrant     =  657 if `2'==2020;
 replace maxefc       = 5576 if `2'==2020;
 replace minstepgrant =  745 if `2'==2020;
 replace maxstepefc   = 5500 if `2'==2020;

 replace maxgrant     = 6345 if `2'==2021;
 replace mingrant     =  639 if `2'==2021;
 replace maxefc       = 5711 if `2'==2021;
 replace minstepgrant =  695 if `2'==2021;
 replace maxstepefc   = 5700 if `2'==2021;

 replace maxgrant     = 6495 if `2'==2022;
 replace mingrant     =  672 if `2'==2022;
 replace maxefc       = 5846 if `2'==2022;
 replace minstepgrant =  745 if `2'==2022;
 replace maxstepefc   = 5800 if `2'==2022;
} ;

replace `1' = 0;
replace `1' = mingrant if `3'<=maxefc;
replace `1' = minstepgrant+100*int((maxstepefc-`3')/100)
              if `3'<=maxstepefc;
replace `1' = maxgrant if `3'==0;

replace `1' = . if !inrange(`2',2008,2022);
replace `1' = . if `3'==.;

drop maxgrant mingrant maxefc minstepgrant maxstepefc;
end;