Rewrite STATA codes featured in 620s Series with R