function [setSelected22, setSelected21]= phase2Only(Y,X,setSelected2in3,L2)
    

[n,d]=size(X);
    numSelectedTwice=size(setSelected2in3,1);
%%% Constructing square for setSelectedTwice %%%
    dimSquare2=ceil(sqrt(numSelectedTwice)); %round up to the nearest integer the square root of the number of selected variables
    nearestSquare2=dimSquare2^2;
    remainderSquare2=nearestSquare2-numSelectedTwice;
    square2=reshape([setSelected2in3;zeros(remainderSquare2,1)],dimSquare2,dimSquare2);
    square2(:,all(square2==0,1))=[];
    squareSelect2=zeros(size(square2));
    % traverse the square column wise then row wise
    for indR=1:size(square2,1)
        if size(nonzeros(square2(indR,:)),1)>0
            subsetX=X(:,nonzeros(square2(indR,:)));
            regressX=[ones(n,1),subsetX];
                    [~,tStat]=regress_hsb(Y,regressX);
                    tStat(1)=[];
                    k=size(tStat,1);
                    tCrit=tinv(1-L2/2, n-(k+1));
                    idxSelected=find((abs(tStat))>tCrit);
            if size(idxSelected,1)>0
                squareSelect2(indR,idxSelected)=squareSelect2(indR,idxSelected)+1;
            end
        end
    end % indR
    for indC=1:size(square2,2)
        if size(nonzeros(square2(:,indC)),1)>0
            subsetX=X(:,nonzeros(square2(:,indC)));
            regressX=[ones(n,1),subsetX];
                    [~,tStat]=regress_hsb(Y,regressX);
                    tStat(1)=[];
                    k=size(tStat,1);
                    tCrit=tinv(1-L2/2, n-(k+1));
                    idxSelected=find((abs(tStat))>tCrit);
            if size(idxSelected,1)>0
                squareSelect2(idxSelected,indC)=squareSelect2(idxSelected,indC)+1;
            end
        end
    end % indC
    if any(squareSelect2(:)>1)
        setSelected22=square2(find(squareSelect2>1)); %pick out the indices of the variables selected 3 times
    else
        setSelected22=[];
    end
    if any(squareSelect2(:)>0)
        setSelected21=square2(find(squareSelect2>0)); % pick out the indices of the variables selected twice
    else
        setSelected21=[];
    end
end

