program define SsPIA_keepvar,
	version 9
	syntax varlist [if], gen(namelist)
	marksample touse
	tokenize `varlist'
	#delimit;
	tempvar raime rq rbyr;

	///1. Assign Data to Variables -------------------

	qui gen `raime'    = `1'  if `touse';
	qui gen `rq'       = `2'  if `touse';
	qui gen `rbyr'     = `3'  if `touse';

	///2. Get Bendpoints for PIA formula
	///(based on year reach 60)

	noi tab `touse';

	tempvar y60 nwi60;
	qui gen `y60' = `rbyr' + 60 if `touse';
	egen `nwi60' = nwi(`y60') if `touse';

	tempname nwi77 b77_1 b77_2 pia_mtr1 pia_mtr2 pia_mtr3 pia_minrate;
	scalar `nwi77' = 9779.44;
	scalar `b77_1' = 180;
	scalar `b77_2' = 1085;

	tempvar bend1 bend2;
	qui gen `bend1' = (`nwi60'/`nwi77')*`b77_1' if `touse';
	qui gen `bend2'  = (`nwi60'/`nwi77')*`b77_2' if `touse';

	tempvar pia pia_min;
	scalar `pia_mtr1' = 0.9;
	scalar `pia_mtr2' = 0.32;
	scalar `pia_mtr3' = 0.15;
	scalar `pia_minrate' = 11.50;

	qui gen `pia' =  `pia_mtr1'*min(`raime',`bend1')
			+ `pia_mtr2'*min(max(`raime'-`bend1',0),`bend2'-`bend1')
			+ `pia_mtr3'*max(`raime'-`bend2',0) if `touse';

	qui gen `pia_min' = `pia_minrate'*min(max((`rq'/4)-10,0),30)	if `touse';
	qui replace `pia' = max(`pia',`pia_min') if `touse';
	tokenize `gen';
	qui rename `pia' `1';

	foreach x in y60 nwi60 bend1 bend2 {;
		noi dis "`x'" ;
		gen `x' = ``x'';
	};

end;