*Stata programming by Example *Tutorial 6 **Looking at extended macros **Stata has lots of extended macros help extended_fcn *--------------Start Example 1 ----------------* clear input str40 a "this is a string that we wish to break up" end list local st= a[1] display "`st'" local len: length local st display "`len'" local length1=`len'/4 forvalues i=1/4 { local aa : piece `i' `length1' of "`st'" display in text "`aa'" } *--------------End Example----------------------* variable label varname *--------------Start Example 2 ----------------* sysuse auto, clear foreach i of varlist _all { //going through all variables local aa : variable label `i' display in text "`aa'" } *--------------End Example----------------------* *--------------Start Example 3 ----------------* sysuse auto, clear quiet sum forvalues i=1/`=_N'{ if `i'==1 local make1= make[`i'] else local make= "`make'" + " "+ make[`i'] } display "`make'" local macname : list uniq make display "`macname'" *--------------End Example----------------------* *--------------Start Example 4 ----------------* local words "this is a list of words" local macname : word count `words' display "`macname'" *--------------End Example----------------------* *End tutorial 6 - programming Stata