Dear all,
I am currently working on my masterthesis. For this thesis, I am preparing a dataset which involves creating new variables.
I have a time panel data set that identifies each observations by a company code (cik) and a specific time period (a combination of year and quarter: fyq "2008Q2").
So for each cik, I have multiple observations for different time periods.
Now, I want to create a new variable which must be equal to the year of fyq for the first observation of cik code. So e.g.:
For each of the observations below I want that newvariable is equal to 2006.
cik fyq
0000921082 2006Q4
0000921082 2007Q1
0000921082 2007Q2
0000921082 2007Q3
0000921082 2007Q4
0000921082 2008Q1
0000921082 2008Q2
0000921082 2008Q4
0000921082 2009Q1
And for these observations I want that newvariable is equal to 2007
cik fyq
0001009976 2007Q1
0001009976 2007Q2
0001009976 2007Q3
0001009976 2007Q4
0001009976 2008Q1
0001009976 2008Q2
0001009976 2008Q4
0001009976 2009Q1
0001009976 2009Q3
0001009976 2010Q1
0001009976 2010Q2
0001009976 2010Q3
0001009976 2010Q4
0001009976 2011Q3
All the observations are available in the same dataset.
How can I achieve this?
Thanks in advance!
Iris
Related Posts with Generate variable with conditions
Help in creating grouped bar chartHi, I am using Stata version 17 and trying to create a grouped bar chart like this: Array I use t…
graphicHallo, I am trying to understand and figure out how to actually code/test between one item (Investme…
Skipping and Restarting A LoopHi, I have the following data. I am trying to compute the mean for each occupation category in the …
What does "could not run iputation" meanWhen using did_imputation (a Difference-in-Difference approach), I faced this problem Could not…
How to get the first 3 digit of a variable ?I have a variable receiving 3 types of results: 4-digit number, 3-digit number, and NA For example …
Subscribe to:
Post Comments (Atom)
0 Response to Generate variable with conditions
Post a Comment