Hi,
I need to work with two data frames, so I'm using global macros to store some values so I can then use them in a different data frame (I know it's possible to have multiple data frames in Stata 16 and 17 but I have Stata 15.1). I want to use the 'foreach' loop with a combination of my global macro but I don't know how to implement it properly. I have this code:
forvalues j=1/4 {
replace D_firmsize_`j'=1 if firm_size_`j'_s=="n_employees" & firm_size_threshold_op_`j'==">" & $Numberofemployees2011 >firm_size_lower_`j' & tax_year==2011 & $Numberofemployees2011 !=.
}
Under $Numberofemployees2011 there is a specific number for a specific company.
This works fine. However, I would like to have it for multiple years (2011 - 2020).
I tried this but it's not working:
forvalues i=2011/2020 {
forvalues j=1/4 {
replace D_firmsize_`j'=1 if firm_size_`j'_s=="n_empoyees" & firm_size_threshold_op_`j'==">" & $Numberofemployees`i'>firm_size_lower_`j' & tax_year==`i' & $Numberofemployees`i'!=.
}
}
Could you help me to solve it so I don't have to do it separately for each year?
Thanks a lot!
Tereza
I need to work with two data frames, so I'm using global macros to store some values so I can then use them in a different data frame (I know it's possible to have multiple data frames in Stata 16 and 17 but I have Stata 15.1). I want to use the 'foreach' loop with a combination of my global macro but I don't know how to implement it properly. I have this code:
forvalues j=1/4 {
replace D_firmsize_`j'=1 if firm_size_`j'_s=="n_employees" & firm_size_threshold_op_`j'==">" & $Numberofemployees2011 >firm_size_lower_`j' & tax_year==2011 & $Numberofemployees2011 !=.
}
Under $Numberofemployees2011 there is a specific number for a specific company.
This works fine. However, I would like to have it for multiple years (2011 - 2020).
I tried this but it's not working:
forvalues i=2011/2020 {
forvalues j=1/4 {
replace D_firmsize_`j'=1 if firm_size_`j'_s=="n_empoyees" & firm_size_threshold_op_`j'==">" & $Numberofemployees`i'>firm_size_lower_`j' & tax_year==`i' & $Numberofemployees`i'!=.
}
}
Could you help me to solve it so I don't have to do it separately for each year?
Thanks a lot!
Tereza
Comment