Hi,
I have a panel of 40 countries with 30 years. I need to generate a new variable like in the table:
I have two ideas how to do it, but I don't know the command.
First idea: use bysort country (year): var1-vector(c00,c01), but I don't know how to tell stata to use the vector(c00,c01)
Second idea: generate new variable repeating the vector(c00,c01) and than subtract this new variable from var1. Again I don't know how to generate this variable of the repeating sequence.
I will need a simple solution since the reference country (the data that I subtract) will be changing.
Many thanks in advance for any help!
Best,
Martin Stoyanov
I have a panel of 40 countries with 30 years. I need to generate a new variable like in the table:
country | year | var1 | new variable |
A | 2000 | a00 | a00-c00 |
A | 2001 | a01 | a01-c01 |
B | 2000 | b00 | b00-c00 |
B | 2001 | b01 | b01-c01 |
C | 2000 | c00 | 0 |
C | 2001 | c01 | 0 |
I have two ideas how to do it, but I don't know the command.
First idea: use bysort country (year): var1-vector(c00,c01), but I don't know how to tell stata to use the vector(c00,c01)
Second idea: generate new variable repeating the vector(c00,c01) and than subtract this new variable from var1. Again I don't know how to generate this variable of the repeating sequence.
I will need a simple solution since the reference country (the data that I subtract) will be changing.
Many thanks in advance for any help!
Best,
Martin Stoyanov
Comment