Dear Statalisters,
I am quite new in stata and I am preparing my data for an event study.
I have a problem creating a loop that stores the value of a variable for a specific row in my dataset as a local macro. This stored macro will later be used in the loop in my preperation.
I have created an exampel to illustrate what i mean:
If I have a dataset looking like this:
And I have created the following code:
foreach l of var1 {
local v = var2
display `v'
}
I would in this case like to get the output displayed:
3
6
7
1
12
7
12
2
4
8
The numbers above is just an example and a simplification of my dataset, but the main problem for me is the same. Stata stores the value of var2 for the first row as v. In this case "3".
I would appreciate any help I can get
Regards
I am quite new in stata and I am preparing my data for an event study.
I have a problem creating a loop that stores the value of a variable for a specific row in my dataset as a local macro. This stored macro will later be used in the loop in my preperation.
I have created an exampel to illustrate what i mean:
If I have a dataset looking like this:
var1 | var2 |
1 | 3 |
2 | 6 |
3 | 7 |
4 | 1 |
5 | 12 |
6 | 7 |
7 | 12 |
8 | 2 |
9 | 4 |
10 | 8 |
foreach l of var1 {
local v = var2
display `v'
}
I would in this case like to get the output displayed:
3
6
7
1
12
7
12
2
4
8
The numbers above is just an example and a simplification of my dataset, but the main problem for me is the same. Stata stores the value of var2 for the first row as v. In this case "3".
I would appreciate any help I can get
Regards
Comment