%
%  This code, tuitionanal2016.m calculates the 
%   average cost over 4 years for an In-state student to attend 
%   the University of Tennessee Knoxville
%   It includes all tuition and fees but does not include any housing,
%   living or other expenses. 
%   It takes into account the Lottery (Hope) scholarships and assumes 
%   that every in-state student qualifies for this scholarship 
%   upon entry to UTK. it applies the available data on fraction of
%   students who lose the scholarship. These data are based upon a cohort
%    analysis carried out by OIRA that gives the fraction of scholarship holders
%    who retain the Hope scholarship across their 4 years at UTK, based on cohorts from 
%    2005-2006 to 2014-2015. While there is some variation from year to year in 
%    the retention fractions, this variation is not large and does not have any 
%     trend over time. Therefore, this code uses the average retention
%     fractions computed over the 10 years of data. These retention fractions 
%     are:
%
%      First year to second year    70.4%
%      First year to third year     66.9% 
%      First year to fourth year    57.6%  
%     so the fractional retention for each year are
%       
%      First year to second year    70.4%
%      Second year to third year    95.0% 
%      First year to fourth year    86.1%  
%
%   The code computes the average cost for students using these values for
%   retention of the Hope scholarship and computes the maximum 4-year cost
%   to attend UT for each entering class (e.g. assuming there is no scholarship
%   at all) and the minimum cost (e.g. assuming the student retains the Hope
%    scholarship each year). 
%
%    The calculation assumes a 3% increase per year in tuition and fees after 
%    the 2015-2016 (FY 2016) academic year.
%
%    The value of the Hope Scholarship has varied somewhat over the years and the
%    assumption is that the student takes 8 semesters to complete a degree (which
%    is generally an underestimate). The value of the Hope scholarship is 
%     $3800 per year for students prior to the 2008 fiscal year (e.g. 2007-2008
%     academic year) and $4000 per year from 2008 to present except students
%     entering Fall 2015 (FY2016) receive $3500 for the first two years and
%     $4500 per year for second two years.  
%  
%   The variable x contains the tuition cost per year (two semesters) including fees
%     starting with the 1998-1999 academic year
%
% x=[2264 2604 2812 3234 3476 3788 4086 4618 4830 5120];
%
   x=2*[1372 1552 1681 1892 2028 2225 2374 2645 2811 2966 3125 3425 3691 4198 4546 4842 5138 5393];
%
%   set the tuition and fees for 2016-17 and later years to increase by 3% per year
%
for i=1:4
    x(18+i)=x(17+i)*1.03
   end;
%
%  The variable y holds the average cost calculation.
%  Set the total cost for students entering FY1999 to FY2005 to be the sum of 
%   all tuition and fees since they did not have a Hope scholarship any year
%
for i=1:6
y(i)=x(i)+x(i+1)+x(i+2)+x(i+3)
end;
%
%  Set the average cost for each cohort based on reducing each year of costs by the Hope 
%   scholarship for those that have it and by the full cost for those that lose
%   the scholarship
%
%  The vector a gives the fraction retention from year to year so that a(1) give
%    the retention of Hope from 1st to 2nd year, a(2) from 1st to third and 
%     a(3) from 1st to 4th
%
a=[.704 .669 .576];
%
%   First compute mean cost for years in which $4000 Hope was phased in
%
y(7)=(x(7)-3800)+(1-a(1))*x(8)+a(1)*(x(8)-3800)+(1-a(2))*x(9)+a(2)*(x(9)-3800)+(1-a(3))*x(10)+a(3)*(x(10)-4000);
y(8)=(x(8)-3800)+(1-a(1))*x(9)+a(1)*(x(9)-3800)+(1-a(2))*x(10)+a(2)*(x(10)-4000)+(1-a(3))*x(11)+a(3)*(x(11)-4000);
y(9)=(x(9)-3800)+(1-a(1))*x(10)+a(1)*(x(10)-4000)+(1-a(2))*x(10)+a(2)*(x(10)-4000)+(1-a(3))*x(11)+a(3)*(x(11)-4000);
%
%  Now compute the mean cost for years in which Hope was $4000 per year all years
%
for j=10:17
   y(j)=(x(j)-4000)+(1-a(1))*x(j+1)+a(1)*(x(j+1)-4000)+(1-a(2))*x(j+2)+a(2)*(x(j+2)-4000)+(1-a(3))*x(j+3)+a(3)*(x(j+3)-4000)
   end;
%
%  Now compute the mean cost for years 2015 and 2016 for which the Hope had different levels
%
y(18)=(x(18)-3500)+(1-a(1))*x(19)+a(1)*(x(19)-3500)+(1-a(2))*x(20)+a(2)*(x(20)-4500)+(1-a(3))*x(21)+a(3)*(x(21)-4500);
y(19)=(x(19)-3500)+(1-a(1))*x(20)+a(1)*(x(20)-3500)+(1-a(2))*x(21)+a(2)*(x(21)-4500)+(1-a(3))*x(22)+a(3)*(x(22)-4500);
%
z=[1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017];
%axis([1999 2008 0 20000]);
%plot(z,y,'*');
%
%  Now compute the minimum cost assuming Hope every year (in ymin)
%  and th maximum cost assuming Hope only for first year (in ymax)
%
ymin(7)=x(7)+x(8)+x(9)+x(10)-3*3800-4000;
ymin(8)=x(8)+x(9)+x(10)+x(11)-2*3800-2*4000;
ymin(9)=x(9)+x(10)+x(11)+x(12)-3800-3*4000;
ymax(7)=x(7)+x(8)+x(9)+x(10)-3800;
ymax(8)=x(8)+x(9)+x(10)+x(11)-3800;
ymax(9)=x(9)+x(10)+x(11)+x(12)-3800;
%
for k=10:17
   ymin(k)=x(k)+x(k+1)+x(k+2)+x(k+3)-4*4000
   ymax(k)=x(k)+x(k+1)+x(k+2)+x(k+3)-4000
   end;
ymin(18)=x(18)+x(19)+x(20)+x(21)-2*3500-2*4500;
ymin(19)=x(19)+x(20)+x(21)+x(22)-2*3500-2*4500;
ymax(18)=x(18)+x(19)+x(20)+x(21)-3500;
ymax(19)=x(19)+x(20)+x(21)+x(22)-3500;
%
%   Now to graph these in sections, set up za and ya for
%   the first 6 years of data, zb and yb for years 7-19
%   
for jj=1:6
    za(jj)=z(jj)
    ya(jj)=y(jj)
end;
for ii=7:19
    zb(ii-6)=z(ii)
    yb(ii-6)=y(ii)
end;

% Create plot first for first 6 years of data then hold
%   the plot to add the other years of average data
%
plot(za,ya,'-*k')
axis([1999 2017 0 45000]);
set(gca,'YTickLabel',{'0','5000','10000','15000','20000','25000','30000','35000','40000','45000'});
hold on 
plot(zb,yb,'-*k')

% Create x label
xlabel({'Fiscal year of first year at UTK'});

% Create ylabel
ylabel({'Average 4-year in-state tuition cost'});

% Create title
title({'Total average cost for 4 years at UTK for in-state students'});

%  Create arrays for the ymin and ymax that are shifted by 6 
%   since these data don't apply during the first 6 years
%   and place these in arrays ymin2 and ymax2 and plot them 
%   against the appropriate years in z2  
for kk=7:19
    ymin2(kk-6)=ymin(kk)
    ymax2(kk-6)=ymax(kk)
    z2(kk-6)=z(kk)
    y2(kk-6)=y(kk)
end;


plot(z2,ymax2,'--+k')
plot(z2,ymin2,'-.xk')


