Dear users,

I hope that you may help me with the following issue.
I'm running regressions by industry and quarter. In my field, usually authors upload their codes together with the paper. Therefore I'm benefiting from some codes. Nevertheless, not all of them are clear to me

Below you will find the reggression in my analysis
Code:
                                                        
sum indyrqtr
local k=r(max)
set more off
forvalues i=1(1)`k'{
qui reg wca_lagasset interval chsale_rec ppe roa_dum1 roa_dum2 roa_dum3 roa_dum4 roa_dum5 sg_dum1 sg_dum2 sg_dum3 sg_dum4 sg_dum5 mb_dum1 mb_dum2 mb_dum3 mb_dum4 mb_dum5 ==`i'
qui predict mjda2 if indyrqtr==`i', res
qui replace residual=res if indyrqtr==`i'
di `i' " / " `k'
}
As I said, the structure is taken by another paper, which the objective is capture the residuals from the regression by a combination of industry and year quarter

My questions are two:
I got the second half of the codes, i.e.:
Code:
qui reg wca_lagasset interval chsale_rec ppe roa_dum1 roa_dum2 roa_dum3 roa_dum4 roa_dum5 sg_dum1 sg_dum2 sg_dum3 sg_dum4 sg_dum5 mb_dum1 mb_dum2 mb_dum3 mb_dum4 mb_dum5 ==`i'
qui predict mjda2 if indyrqtr==`i', res
qui replace residual=res if indyrqtr==`i'
Nevertheless, to me is puzzling the meaning of the first half, i.e.:
Code:
sum indyrqtr
local k=r(max)
set more off
forvalues i=1(1)`k'{
Would you be so kind to explain me the meaning of the above steps?

Finally, if I run the regression to my sample, I obtained the following error message
Code:
invalid syntax
r(198);
Is difficult to me to understand about what is related



Below an example of my data

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str7 indyrqtr float(wca_lagasset interval chsale_rec ppe) byte(roa_dum1 roa_dum2 roa_dum3 roa_dum4 roa_dum5)
"1320094"           .          . .           . 1 0 0 0 0
"5920094"           .          . .           . 1 0 0 0 0
"1020094"           .          . .           . 1 0 0 0 0
"1320094"           .          . .           . 1 0 0 0 0
"7320094"           .          . .           . 1 0 0 0 0
"2820094"           .          . .           . 1 0 0 0 0
"2820094"           .          . .           . 1 0 0 0 0
"1320094"           .          . .           . 1 0 0 0 0
"7320094"           .          . .           . 1 0 0 0 0
"2820094"           .          . .           . 1 0 0 0 0
"3620094"           .          . .           . 1 0 0 0 0
"2820094"           .          . .           . 1 0 0 0 0
"3820094"           .          . .           . 1 0 0 0 0
"1320094"           .          . .           . 1 0 0 0 0
"7320094"           .          . .           . 1 0 0 0 0
"4820094"           .          . .           . 1 0 0 0 0
"4920094"           .          . .           . 1 0 0 0 0
"7320094"           .          . .           . 1 0 0 0 0
"1020094"           .          . .           . 1 0 0 0 0
"2820094"           .          . .           . 1 0 0 0 0
"3620094"           .          . .           . 1 0 0 0 0
"2820094"           .          . .           . 1 0 0 0 0
"1020094"           .          . .           . 1 0 0 0 0
"7320094"           .          . .           . 1 0 0 0 0
"7320094"           .          . .           . 1 0 0 0 0
"3820094"           .          . .           . 1 0 0 0 0
"1020094"           .          . .           . 1 0 0 0 0
"5920094"           .          . .           . 1 0 0 0 0
"4820094"           .          . .           . 1 0 0 0 0
"1320094"           .          . .           . 1 0 0 0 0
"1020094"           .          . .           . 1 0 0 0 0
"7320094"           .          . .           . 1 0 0 0 0
"3820094"           .          . .           . 1 0 0 0 0
"2820094"           .          . .           . 1 0 0 0 0
"3820094"  .022258123    .179501 .   .28774008 1 0 0 0 0
"5020094"           .          . .           . 1 0 0 0 0
"3620094"           .          . .           . 1 0 0 0 0
"1320094"           .          . .           . 1 0 0 0 0
"1020094"           .          . .           . 1 0 0 0 0
"7320094"           .          . .           . 1 0 0 0 0
"2020094"           .          . .           . 1 0 0 0 0
"7320094"           .          . .           . 1 0 0 0 0
"7320094"           .          . .           . 1 0 0 0 0
"1020094"           .  .06554368 .   .04230189 1 0 0 0 0
"3620094" -.033005677  .04236929 .   .08465384 1 0 0 0 0
"1320094"           .          . .           . 1 0 0 0 0
"2820094"           .          . .           . 1 0 0 0 0
"3820094"           .          . .           . 1 0 0 0 0
"1020094"           .          . .           . 1 0 0 0 0
"5020094"           .          . .           . 1 0 0 0 0
"7320094"           .          . .           . 1 0 0 0 0
"7320094"           .          . .           . 0 1 0 0 0
"7320094"           .          . .           . 0 1 0 0 0
"7320094"           .          . .           . 0 1 0 0 0
"7320094"           .          . .           . 0 1 0 0 0
"4820094"           .          . .           . 0 1 0 0 0
"3620094"           .          . .           . 0 1 0 0 0
"5020094"           .          . .           . 0 1 0 0 0
"2020094"           .          . .           . 0 1 0 0 0
"4820094"           .          . .           . 0 1 0 0 0
"4820094"           .          . .           . 0 1 0 0 0
"1320094"   .06486585 .006863748 . .0015168883 0 1 0 0 0
"2020094"           .          . .           . 0 1 0 0 0
"7320094"           .          . .           . 0 1 0 0 0
"2820094"           .          . .           . 0 1 0 0 0
"7320094"           .          . .           . 0 1 0 0 0
"7320094"           . .016491037 .   .02086116 0 1 0 0 0
"3620094"           .          . .           . 0 1 0 0 0
"2820094"           .          . .           . 0 1 0 0 0
"7320094"           .          . .           . 0 1 0 0 0
"4820094"           .          . .           . 0 1 0 0 0
"3620094"           .          . .           . 0 1 0 0 0
"7320094"           .          . .           . 0 1 0 0 0
"8720094"           .          . .           . 0 1 0 0 0
"8720094"           .          . .           . 0 1 0 0 0
"7320094"           .          . .           . 0 1 0 0 0
"1020094"           .          . .           . 0 1 0 0 0
"4820094"           .          . .           . 0 1 0 0 0
"1020094"           .          . .           . 0 1 0 0 0
"2820094"           .          . .           . 0 1 0 0 0
"5920094"           .          . .           . 0 1 0 0 0
"1320094"           .          . .           . 0 1 0 0 0
"5020094"           .          . .           . 0 1 0 0 0
"5020094"           .          . .           . 0 1 0 0 0
"4820094"           .          . .           . 0 1 0 0 0
"2020094"           .          . .           . 0 1 0 0 0
"7320094"           .          . .           . 0 1 0 0 0
"7320094"           .          . .           . 0 1 0 0 0
"1020094"           .          . .           . 0 1 0 0 0
"8720094"           .          . .           . 0 1 0 0 0
"3620094"           .          . .           . 0 1 0 0 0
"4920094"           .          . .           . 0 1 0 0 0
"2020094"           .          . .           . 0 1 0 0 0
"7320094"           .          . .           . 0 1 0 0 0
"7320094"           .          . .           . 0 1 0 0 0
"7320094"           .          . .           . 0 1 0 0 0
"7320094"           .          . .           . 0 1 0 0 0
"3820094"           .          . .           . 0 1 0 0 0
"4920094"           .          . .           . 0 1 0 0 0
"8720094"           .          . .           . 0 0 1 0 0
end

Many thanks for your time and help