function sd = sd_boot(var,n,conf)

%sd_boot    Calculates standard deviations with bootstrapped error bands
%   sd_boot(VAR,K,N,CONF) calculates the standard deviation of VAR_t for 
%     N bootstrapped samples, and outputs the median value along with error
%     band at significance CONF.
%
%   VAR = Tx1 data vector. 
%   N = number of boostrap replications.
%   CONF = significance of reported error band.  Must be between 0 and 1.
%
%   CC = 1-by-3 vector of calculated statistics
%     Col 1 gives lower boundary of error band.
%     Col 2 gives median values across the bootstrapped samples.
%     Col 3 gives upper boundary of error band.

t = size(var,1);
var = var-mean(var);
var_mat = repmat(var,1,n);

draw = randi(t,t,n);
var0 = var_mat(draw);
boot_repl = std(var0);
boot_repl = sort(boot_repl,2);
low = round(n*(1-conf));   
high = round(n*conf);
sd = zeros(1,3);
sd(:,1) = boot_repl(:,low);
sd(:,2) = median(boot_repl,2);
sd(:,3) = boot_repl(:,high);

%                                               G. Ramey - UCSD - 4/16/2019
