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
Keep running a replace command until (0 real changes made)Hello! I have a paneldata with the ages of individuals with around 50 million observations. The age …
Matching values from a panel dataset to a cross-section datasetDear all, I hope you can help me with what seems to be a rather simple issue that i cannot seem to f…
Is RGB Ram any good for Stata?I use a huge dataset, so the speed is an issue. It looks like RGB Ram is a thing, but is it also hel…
Formatting Strings: same words being recognized as "different"Hello, I imported a dataset from Excel, but the string variables are being recognized as "different…
Announcing the expanded (and now correctly described) 'tolerance' command to calculate tolerance intervals (normal distribution)I have rewritten the 'tolerance' command which is now described correctly*. I've used percentofpop(#…
Subscribe to:
Post Comments (Atom)
0 Response to Generate variable with conditions
Post a Comment