I'm having problem with data manipulation, but I don't know how to start. I'm using STATA 12.0 for MAC.
My dataset looks like this:
Variables "gamma" and "beta" depend on both "firm_id" and "investor_id", and variable "zeta" and "sic code" depends only on "firm_id".
With that in mind, I shall denote gamma_{k,i} as the value of "gamma" with investor_id = k and firm_id = i.
With the data, I want to compute the following variable "X_i" for each firm "i" in each year:
For each firm "i" in each year,
X_i = sum_{Firms j's with the same sic code in the year} sum_{All investors k's in the year} zeta_{j} gamma_{k,i} beta_{k,j}, or
Array ,
where if gamma_{k,i} or beta_{k,j} is missing, then replace the missing gamma and beta with zero.
As a beginner in any statistical software, I was trying to find how to start with the problem but have no clue. Do I have to learn loops or are there any brilliant ways to do the computation?
I would very much appreciate any helps. Thank you!
My dataset looks like this:
year | firm_id | investor_id | gamma | beta | zeta | sic code |
2014 | 1 | 1 | .1 | .21 | .3 | 11 |
2014 | 1 | 2 | .17 | .22 | .3 | 11 |
2014 | 1 | 3 | .12 | .23 | .3 | 11 |
2014 | 2 | 1 | .19 | .24 | .5 | 11 |
2014 | 2 | 2 | .13 | .25 | .5 | 11 |
2014 | 3 | 1 | .15 | .26 | .35 | 12 |
2014 | 3 | 2 | .15 | .27 | .35 | 12 |
2014 | 3 | 3 | .14 | .28 | .35 | 12 |
. | ||||||
. | ||||||
2015 | 1 | 1 | .1 | .21 | .3 | 11 |
2015 | 1 | 3 | .1 | .23 | .3 | 11 |
2015 | 2 | 1 | .2 | .13 | .55 | 14 |
2015 | 2 | 2 | .22 | .21 | .55 | 14 |
. | . | |||||
. |
With that in mind, I shall denote gamma_{k,i} as the value of "gamma" with investor_id = k and firm_id = i.
With the data, I want to compute the following variable "X_i" for each firm "i" in each year:
For each firm "i" in each year,
X_i = sum_{Firms j's with the same sic code in the year} sum_{All investors k's in the year} zeta_{j} gamma_{k,i} beta_{k,j}, or
Array ,
where if gamma_{k,i} or beta_{k,j} is missing, then replace the missing gamma and beta with zero.
As a beginner in any statistical software, I was trying to find how to start with the problem but have no clue. Do I have to learn loops or are there any brilliant ways to do the computation?
I would very much appreciate any helps. Thank you!