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
Related Posts with Loop for specific range and store value
Merging two files on multiple criteria and imperfect matching?Hi, I have two data files I want to merge. The issue is I don't have an ID column shared by both fil…
New on SSC - complexity : computes Complexity Indexes similar to ECI/PCIDear Statalisters, This post to announce that I've released complexity - a package to compute compl…
xtline and standard deviationHello everyone, I need to draw a lineplot for paneldata. I used the following command: collapse (m…
Xtqreg-qunaitle regression in a panel dataDear Joao Santos Silva I am trying to run fixed effects quantile regression for a panel of 260 firm…
create a new variable from weighted variables?Hello everyone, I'm now stuck into this one: I have a data-set and a (sample) weight variable. Due …
Subscribe to:
Post Comments (Atom)
0 Response to Loop for specific range and store value
Post a Comment