Hello,

I am working on a firm level panel data. I am trying to create a new variable by subtracting avg_ex_firm (in a t-1 period) from export (period t). But I have got a missing value in every observation for my new variable. Could you please tell me what I am doing wrong? I am new to Stata.

Here is the codes that I tried to generate new variable.

Code:
generate f6 = export - l.avg_ex_firm

or

by uid (year), sort: gen f6 = export - l.avg_ex_firm
Here is the sample from my panel dataset.

Code:
. xtset uid year
       panel variable:  uid (unbalanced)
        time variable:  year, 2010 to 2020, but with gaps
                delta:  1 unit

. xtdescribe

     uid:  1, 2, ..., 4631                                   n =       4631
    year:  2010, 2011, ..., 2020                             T =         11
           Delta(year) = 1 unit
           Span(year)  = 11 periods
           (uid*year uniquely identifies each observation)
uid (unique id for a firm)
year (2010-2020)
export (export by firm i in period t)
avg_ex_firm (average export per firm in a given year)

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float uid int year double export float avg_ex_firm
 1 2011              20622 543023.7
 2 2010                500 486097.4
 3 2013                320 711880.9
 4 2020          14952.982 704694.8
 5 2011  52308.19699999999 543023.7
 6 2015  81.17999999999999 742190.9
 7 2016              76000 697803.1
 8 2010             1015.6 486097.4
 8 2015          25048.749 742190.9
 9 2010          11009.199 486097.4
10 2011                400 543023.7
11 2010           1072.804 486097.4
11 2013           6321.228 711880.9
11 2017               3532 628858.7
12 2015  926.3900000000001 742190.9
13 2012              14800 527748.2
14 2010          24815.209 486097.4
14 2012               3106 527748.2
15 2013           4359.015 711880.9
16 2010                 43 486097.4
16 2014          32218.763 788829.9
17 2010             340.79 486097.4
17 2013               1200 711880.9
18 2016 101282.03099999999 697803.1
19 2012             6105.9 527748.2
20 2016 112983.16999999998 697803.1
21 2017            1014.68 628858.7
22 2016               5160 697803.1
23 2010                315 486097.4
24 2020                500 704694.8
25 2016 1909.7040000000002 697803.1
end
Thank you