program define StateTax, rclass version 9 syntax varlist [if] , gen(namelist) marksample touse tokenize `varlist' #delimit ; ///1. Assign Data to Variables ------------------- tempvar ry_earn sy_earn ry_pub sy_pub y_ben y_pen y_ot y_as mar rage sage y_total; ///1. Assign Data to Variables ------------------- qui gen `ry_earn' = `1' if `touse'; qui gen `sy_earn' = `2' if `touse'; qui gen `ry_pub' = `3' if `touse'; qui gen `sy_pub' = `4' if `touse'; qui gen `y_ben' = `5' if `touse'; qui gen `y_pen' = `6' if `touse'; qui gen `y_ot' = `7' if `touse'; qui gen `y_as' = `8' if `touse'; qui gen `mar' = `9' if `touse'; qui gen `rage' = `10' if `touse'; qui gen `sage' = `11' if `touse'; qui gen `y_total' = `ry_earn' + `sy_earn' + `ry_pub' + `sy_pub' + `y_ben' + `y_pen' + `y_ot' + `y_as'; /// taxes: Detroit, Michigan tempname city_ded state_ded state_atr city_atr city_tc_thres1 city_tc_thres2 city_tc_mtr1 city_tc_mtr2 city_tc_mtr3; scalar `city_ded' = 750; scalar `state_ded' = 3100; scalar `state_atr' = 0.04; scalar `city_atr' = 0.0255; scalar `city_tc_thres1' = 100; scalar `city_tc_thres2' = 150; scalar `city_tc_mtr1' = 0.20; scalar `city_tc_mtr2' = 0.10; scalar `city_tc_mtr3' = 0.05; /// taxes: Detroit, Michigan tempvar city_taxble state_taxble city_taxgross stax city_tc ctax; qui gen `city_taxble' = max(`y_total' - `city_ded'*(1+`mar'),0) if `touse'; qui gen `state_taxble' = max(`y_total' - `state_ded'*(1+`mar'),0) if `touse'; qui gen `city_taxgross' = `city_taxble'*`city_atr' if `touse'; qui gen `stax' = `state_taxble'*`state_atr' if `touse'; qui gen `city_tc' = `city_tc_mtr1'*min(`city_tc_thres1',`city_taxgross') + `city_tc_mtr2'*min(`city_tc_thres2' - `city_tc_thres1',max(`city_taxgross' - `city_tc_thres1',0)) + `city_tc_mtr3'*max(`city_taxgross' - `city_tc_thres2',0) if `touse'; qui gen `ctax' = max(`city_taxgross' - `city_tc',0) if `touse'; tokenize `gen'; qui gen `1' = `stax' if `touse'; qui gen `2' = `ctax' if `touse'; end;