Hi,
I have two data sets. First one has variables named "start","end" ,and "stock" and the other one has variables "num", "stock" and "price".
I want to generate a new variable in my first data set which has the average price of each stock which it's "num" is greater than "start" and smaller than "end".
I have appended these two data sets and renamed the name of the "name" variable in second data set to "name2".
So my data set is like:
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input byte(start end) str1(stock stock2) byte(num price)
1 3 "a" ""  .  .
2 5 "b" ""  .  .
5 6 "a" ""  .  .
3 4 "c" ""  .  .
4 6 "b" ""  .  .
5 7 "a" ""  .  .
1 2 "c" ""  .  .
. . ""  "a" 1  0
. . ""  "a" 2  2
. . ""  "a" 3  3
. . ""  "a" 4  9
. . ""  "a" 5  9
. . ""  "a" 6  5
. . ""  "a" 7  4
. . ""  "b" 1 10
. . ""  "b" 2  9
. . ""  "b" 3 10
. . ""  "b" 4  5
. . ""  "b" 5 10
. . ""  "b" 6  7
. . ""  "b" 7  1
. . ""  "c" 1  7
. . ""  "c" 2  4
. . ""  "c" 3  4
. . ""  "c" 4  1
. . ""  "c" 5  2
. . ""  "c" 6  5
. . ""  "c" 7  0
end

A new variable ,called "mean_price", should have (0+2+3)/3 for the first row and (10+7)/2 for the second row and so on until the 7th row.
Thanks for your attention.