Hello
I am new to Stata. One of my assignment is to replicate Fama French 3. I did it in Matlab; however instructor want it to be done in Stata. Here is the problem, in Matlab, I can easily create new matrixes, locate value, run some operation and store value in anywhere I want. However, in Stata I just dont know how.
Please refer to Excel file to make it easier to visualize. My data is unbalanced.
Question 01: Create a list of new ID_New.
I have company unique key name is "ID_CRSP". I want to create a list of distinct new ID following order from 1 till end (see Excel). The code I use is "gen ID = group(ID_CRSP)". Is this code always create list of integer from 1 with incremental 1. I just want to make sure for latter coding.
Question 02: I want to run the regression for:
- Every ID
- Starting at time t = 6 with step of 2. So it is 6,8,10,...till ending year 20
- Regress Y_mkt on X1_ret for exactly using lag value from (t-5) to (t-1). You can see at time 6, I regress from time 1-5. At time 8, because we miss time 7, so regress has only 4obs from 2 to 6.
- Return the slope coefficient and store exactly at Result_1, for time 6, 8, 10, ...
The hacking way is to abuse egen to create the condition this is inefficient when managing large data set.
Question 03: Say latter I want to retreive a specific value in Result_1, ID=1, time = 12, then how should I locate that?
Thank you for reading
Phan
0 Response to Loop for specific range and store value
Post a Comment