Hi Statalist. I'm having a bit of trouble finding the help file that will let me achieve something particular with a foreach loop.
I have several variables in pairs. e.g a_com and a_firm, b_com and b_firm, c_com and c_firm, etc. I want to create new variables for the difference between each. Once I've got the difference variable, it's easy to use a "foreach var" command to manipulate them. However, I can't work out how to use a loop to take the differences. I think the code I need is something like:
foreach i in a b c etc {
gen `i'_dif = `i'_firm - `i'_com
{
But it's not quite working. Can anyone help me out?
Thanks,
Arthur
I have several variables in pairs. e.g a_com and a_firm, b_com and b_firm, c_com and c_firm, etc. I want to create new variables for the difference between each. Once I've got the difference variable, it's easy to use a "foreach var" command to manipulate them. However, I can't work out how to use a loop to take the differences. I think the code I need is something like:
foreach i in a b c etc {
gen `i'_dif = `i'_firm - `i'_com
{
But it's not quite working. Can anyone help me out?
Thanks,
Arthur
Comment