Hi all,

I need some help in extracting data from a column. I am trying to find a way to do so without much eyeballing of the data. So below is an example of my dataset:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str3 location str7 time float unemp_data byte pt_output float(spell quarters_to_start unemp_time)
"AUT" "1969-Q1"  2.28056 . 0 22 -35
"AUT" "1969-Q2" 1.799027 . 0 22 -34
"AUT" "1969-Q3" 1.735777 . 0 22 -33
"AUT" "1969-Q4" 1.718443 . 0 22 -32
"AUT" "1970-Q1" 1.538099 . 0 22 -31
"AUT" "1970-Q2" 1.328224 . 0 22 -30
"AUT" "1970-Q3" 1.198998 . 0 22 -29
"AUT" "1970-Q4" 1.225661 . 0 22 -28
"AUT" "1971-Q1" 1.173203 . 0 22 -27
"AUT" "1971-Q2"  1.33824 . 0 22 -26
"AUT" "1971-Q3" 1.042691 . 0 22 -25
"AUT" "1971-Q4" 1.277456 . 0 22 -24
"AUT" "1972-Q1"  1.15306 . 0 22 -23
"AUT" "1972-Q2" 1.064005 . 0 22 -22
"AUT" "1972-Q3" 1.357699 . 0 22 -21
"AUT" "1972-Q4" 1.039917 . 0 22 -20
"AUT" "1973-Q1" 1.035841 . 0 22 -19
"AUT" "1973-Q2" 1.177305 . 0 22 -18
"AUT" "1973-Q3" 1.108755 . 0 22 -17
"AUT" "1973-Q4" .9943526 . 0 22 -16
"AUT" "1974-Q1"  1.26808 . 0 22 -15
"AUT" "1974-Q2" 1.299121 . 0 22 -14
"AUT" "1974-Q3" 1.308654 1 1 22 -13
"AUT" "1974-Q4" 1.478947 . 1 22 -12
"AUT" "1975-Q1" 1.452747 . 1 22 -11
"AUT" "1975-Q2"  1.88046 2 1 22 -10
"AUT" "1975-Q3" 1.734818 . 1 22  -9
"AUT" "1975-Q4" 1.982104 . 1 22  -8
"AUT" "1976-Q1" 1.854092 . 1 22  -7
"AUT" "1976-Q2" 1.830328 . 1 22  -6
"AUT" "1976-Q3" 1.804084 . 1 22  -5
"AUT" "1976-Q4" 1.657884 . 1 22  -4
"AUT" "1977-Q1" 1.556965 . 1 22  -3
"AUT" "1977-Q2" 1.492262 . 1 22  -2
"AUT" "1977-Q3" 1.743809 . 1 22  -1
"AUT" "1977-Q4" 1.708798 . 1 22   0
"AUT" "1978-Q1"  1.78792 . 1 22   1
"AUT" "1978-Q2" 2.194976 . 1 22   2
"AUT" "1978-Q3" 2.050228 . 1 22   3
"AUT" "1978-Q4" 2.223532 . 1 22   4
"AUT" "1979-Q1" 2.196454 . 1 22   5
"AUT" "1979-Q2" 2.063658 . 1 22   6
"AUT" "1979-Q3"  2.00938 . 1 22   7
"AUT" "1979-Q4" 2.050331 . 1 22   8
"AUT" "1980-Q1" 1.729307 1 2  9   9
"AUT" "1980-Q2" 1.763711 . 2  9  10
"AUT" "1980-Q3" 2.052905 . 2  9  11
"AUT" "1980-Q4" 1.885693 . 2  9  12
"AUT" "1981-Q1" 2.130085 2 2  9  13
"AUT" "1981-Q2" 2.577704 . 2  9  14
"AUT" "1981-Q3"  2.53258 . 2  9  15
"AUT" "1981-Q4" 2.889663 . 2  9  16
"AUT" "1982-Q1" 2.902107 . 2  9  17
"AUT" "1982-Q2" 3.268415 1 3  6  18
"AUT" "1982-Q3" 3.767183 . 3  6  19
"AUT" "1982-Q4" 4.004116 2 3  6  20
"AUT" "1983-Q1" 4.186985 . 3  6  21
"AUT" "1983-Q2" 4.326129 . 3  6  22
"AUT" "1983-Q3" 4.280576 . 3  6  23
"AUT" "1983-Q4"   3.7363 1 4 35  24
"AUT" "1984-Q1" 3.937536 . 4 35  25
"AUT" "1984-Q2" 3.801948 2 4 35  26
"AUT" "1984-Q3" 3.670202 . 4 35  27
"AUT" "1984-Q4" 3.740511 . 4 35  28
"AUT" "1985-Q1" 3.584991 . 4 35  29
"AUT" "1985-Q2" 3.616743 . 4 35  30
"AUT" "1985-Q3" 3.645316 . 4 35  31
"AUT" "1985-Q4" 3.545668 . 4 35  32
"AUT" "1986-Q1" 3.312451 . 4 35  33
"AUT" "1986-Q2" 2.947661 . 4 35  34
"AUT" "1986-Q3" 2.836876 . 4 35  35
"AUT" "1986-Q4" 3.318925 . 4 35  36
"AUT" "1987-Q1" 3.932383 . 4 35  37
"AUT" "1987-Q2" 3.714838 . 4 35  38
"AUT" "1987-Q3" 3.986203 . 4 35  39
"AUT" "1987-Q4" 3.516049 . 4 35  40
"AUT" "1988-Q1" 3.595898 . 4 35  41
"AUT" "1988-Q2" 3.492004 . 4 35  42
"AUT" "1988-Q3" 3.606824 . 4 35  43
"AUT" "1988-Q4" 3.512885 . 4 35  44
"AUT" "1989-Q1" 3.068615 . 4 35  45
"AUT" "1989-Q2" 3.235731 . 4 35  46
"AUT" "1989-Q3" 2.959549 . 4 35  47
"AUT" "1989-Q4" 3.307182 . 4 35  48
"AUT" "1990-Q1" 3.153923 . 4 35  49
"AUT" "1990-Q2" 3.269969 . 4 35  50
"AUT" "1990-Q3" 3.412282 . 4 35  51
"AUT" "1990-Q4" 3.239165 . 4 35  52
"AUT" "1991-Q1" 3.383817 . 4 35  53
"AUT" "1991-Q2"  3.44205 . 4 35  54
"AUT" "1991-Q3"  3.58801 . 4 35  55
"AUT" "1991-Q4" 3.613474 . 4 35  56
"AUT" "1992-Q1" 3.392481 . 4 35  57
"AUT" "1992-Q2" 3.799317 . 4 35  58
"AUT" "1992-Q3" 3.598001 1 5 33  59
"AUT" "1992-Q4" 3.767504 . 5 33  60
"AUT" "1993-Q1" 3.833333 2 5 33  61
"AUT" "1993-Q2" 3.966667 . 5 33  62
"AUT" "1993-Q3" 4.033333 . 5 33  63
"AUT" "1993-Q4"        4 . 5 33  64
end
The column "spell" shows the recession period, so "0" means the recession has not started yet but "1" is the first recession and "2" is second recession and so on. The column "unemp_time" refers to the quarters before a recession, with the variable equals zero when the recession starts. I intend to create 2 new columns: "recession1" and "recession2". So for the first recession, data would be extracted from the column "unemp_data", starting from row 1 to row 33 but I want data to start from row 14 to 46 instead. For the second recession, I want data to be extracted from the column "unemp_data", starting from row 23 to 53 but data to start from 14 to 46 in the new column instead. The reason for the data starting from different rows is because different recessions have different number of quarters before them. I need to know if there is a command that would automate the process. I intend to use this commands:

Code:
gen recession1= unemp_data[_n-13] if _n>=14 in 14/46
gen recession2= unemp_data[_n+19] if _n>= 22 in 22/46
This command still requires some eyeballing of data as different recessions have different number of quarters before them. I am not sure if there exists a command that requires less eyeballing of data. Any help in this area would be greatly appreciated. Thanks!