| |
| |
|
|
| |
| cap prog drop panelcombine |
| prog define panelcombine |
| qui { |
| syntax, use(str asis) paneltitles(str asis) columncount(integer) save(str asis) [CLEANup] |
|
|
| |
| |
| |
| |
|
|
| preserve |
|
|
| tokenize `"`paneltitles'"' |
| |
| local num 1 |
| while "``num''"~="" { |
| local panel`num'title="``num''" |
| local num=`num'+1 |
| } |
|
|
|
|
| tokenize `use' |
| |
| local num 1 |
| while "``num''"~="" { |
| tempfile temp`num' |
| insheet using "``num''", clear |
| save `temp`num'' |
| local max = `num' |
| local num=`num'+1 |
| } |
|
|
| |
| local num 1 |
| while "``num''"~="" { |
| local panellabel : word `num' of `c(ALPHA)' |
| use `temp`num'', clear |
| if `num'==1 { |
| drop if strpos(v1,"Note:")>0 | strpos(v1,"in parentheses")>0 | strpos(v1,"p<0")>0 |
| drop if v1=="\end{tabular}" | v1=="}" |
| |
| cap drop temp |
| g temp = regex(v1,"Variable.*\\\\ \\hline \\\\") |
| |
| replace temp = temp+temp[_n-1] if _n>1 |
| replace temp = temp+temp[_n-1] if _n>1 |
| local nobs = _N + 1 |
| set obs `nobs' |
| gen v2=v1[_n-1] if temp>2 |
| replace v2=v1 if temp<=1 |
| replace v2 = "\multicolumn{`columncount'}{l}{ \linebreak \textbf{\textit{Panel `panellabel': `panel1title'}}} \\" if v2=="" |
| drop v1 temp |
| rename v2 v1 |
| replace v1 = "\hline \\[-1.8ex]" if regex(v1,"\\hline \\hline \\\\.*") & _n>4 |
| } |
| else if `num'==`max' { |
| |
| g temp = regex(v1,"Variable.*\\\\ \\hline \\\\.*") |
| |
| replace temp = temp+temp[_n-1] if _n>1 |
| drop if temp==0 |
| drop temp |
| |
| replace v1 = " \multicolumn{`columncount'}{l}{\linebreak \textbf{\textit{Panel `panellabel': `panel`num'title'}}} \\" if _n==1 |
| } |
| else { |
| |
| g temp = regex(v1,"Variable.*\\\\ \\hline \\\\.*") |
| |
| replace temp = temp+temp[_n-1] if _n>1 |
| drop if temp==0 |
| drop temp |
| |
| replace v1 = " \multicolumn{`columncount'}{l}{\linebreak \textbf{\textit{Panel `panellabel': `panel`num'title'}}} \\" if _n==1 |
| drop if strpos(v1,"Note:")>0 | strpos(v1,"in parentheses")>0 | strpos(v1,"p<0")>0 |
| drop if v1=="\end{tabular}" | v1=="}" |
| replace v1 = "\hline \\[-1.8ex]" if regex(v1,"\\hline \\hline \\\\.*") |
| } |
| save `temp`num'', replace |
| local num=`num'+1 |
| } |
|
|
| use `temp1',clear |
| local num 2 |
| while "``num''"~="" { |
| append using `temp`num'' |
| local num=`num'+1 |
| } |
|
|
| outsheet using `save', noname replace noquote |
|
|
|
|
| if "`cleanup'"!="" { |
| tokenize `use' |
| local num 1 |
| while "``num''"~="" { |
| erase "``num''" |
| local num=`num'+1 |
| } |
| } |
|
|
| restore |
| } |
| end |
|
|