Hello,

I'm trying to create an deflator of the investment for every company in my panel, based of the first observation of this company. I have two different variables that I'd like to deflate, which are, fCAPX and c_mat. Both are proxies of investment per year.

the deflator = ( this year investment / first year investment) * 100

So i'm guessing:

bysort firm_id (year): generate inv_deflator = (c_mat / (c_mat [_n] == 1)) *100 ? Is this correct? Is there a more efficient way of doing this?


Thank you

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float firm_id str16 idnr double(closdate_year ebit depr turn ebta opre) float(fCAPX c_mat)
 1 "FI10290064"    2007    -1000    2000     3000    1000     3000       .     2000
 1 "FI10290064"    2009    -7000       .    11000       .    11000       .        .
 2 "FI26827006"    2016    -1000       .    71000       .    71000       .        .
 3 "FI27388017"    2016        .       .        .       .   100000       .        .
 4 "IT00000020362" 2007  -132476   23908  1841487 -108568  1970409   55787  1950055
 4 "IT00000020362" 2008    41900   24822  2300573   66722  2206105    2984  2233851
 4 "IT00000020362" 2009  -370176   15889  1007198 -354287   928467   13517  1361485
 4 "IT00000020362" 2010  -261684   12797  1263340 -248887  1217213   90705  1512227
 4 "IT00000020362" 2011  -276379   99087  1034239 -177292   942236  -95292  1211531
 4 "IT00000020362" 2012  -196182    5229   539470 -190953   345612       .   730423
 5 "IT00000210054" 2007    -8536    2655   610064   -5881   613005     894   615945
 5 "IT00000210054" 2008    12655    3164   595101   15819   625437   -1694   579282
 5 "IT00000210054" 2009     9288    3811   491656   13099   499725   -1905   478557
 5 "IT00000210054" 2010    -1812    4090   542363    2278   566913    1120   540085
 5 "IT00000210054" 2011    10855    4197   528512   15052   508694     221   513460
 5 "IT00000210054" 2012    10743    1620   444428   12363   439272     666   432065
 5 "IT00000210054" 2013     9901    1274   407241   11175   408549       1   396066
 5 "IT00000210054" 2014    10223    1221   436512   11444   439470     484   425068
 5 "IT00000210054" 2015     8930    1095   367083   10025   365195       0   357058
 5 "IT00000210054" 2016     8028     610   381487    8638   382250       .   372849
 6 "IT00000240408" 2011    -8519    4545    14958   -3974    14962   -6475    18932
 6 "IT00000240408" 2012    45906    8850   131965   54756   148113   17437    77209
 6 "IT00000240408" 2013    69523   10361   173274   79884   173578   21089    93390
 6 "IT00000240408" 2014    44142    9027   143327   53169   180905    2333    90158
 6 "IT00000240408" 2015   114657    8296   263160  122953   316212   13818   140207
 6 "IT00000240408" 2016    25490    8711   151514   34201   171881       .   117313
 7 "IT00000450155" 2007    97374  193022  1707725  290396  1729067  170597  1417329
 7 "IT00000450155" 2008    57731  195338  1785326  253069  1777067   23512  1532257
 7 "IT00000450155" 2009   -59689  175181  1444539  115492  1440234   59240  1329047
 7 "IT00000450155" 2010   -32586  126755  1323801   94169  1282357  112405  1229632
 7 "IT00000450155" 2011  -327049  109354  1091350 -217695  1132447    7538  1309045
 7 "IT00000450155" 2012  -187798   67811  1159131 -119987  1148983   27924  1279118
 7 "IT00000450155" 2013  -211244   70216  1031793 -141028  1026007   93336  1172821
 7 "IT00000450155" 2014  -262980   53017   534215 -209963   534215  383891   744178
 7 "IT00000450155" 2015     -720  103809  1395732  103089  1446358   16882  1292643
 7 "IT00000450155" 2016     9302  100877  1429306  110179  1434313       .  1319127
 8 "IT00000520288" 2007   109754   43306   709721  153060  2041155  287185   556661
 8 "IT00000520288" 2008   -57413  103501   751262   46088   967389   18643   705174
 8 "IT00000520288" 2009   -42826  110437   643837   67611   638687    3219   576226
 8 "IT00000520288" 2010   -77516   81489   461521    3973   564622   18800   457548
 8 "IT00000520288" 2011   -74121   80439   417131    6318   538081    9024   410813
 8 "IT00000520288" 2012  -243357   81879   330940 -161478   319790      57   492418
 8 "IT00000520288" 2013  -158945   21289   302023 -137656   307623     671   439679
 8 "IT00000520288" 2014   -11355   16103   289213    4748   269413    2195   284465
 8 "IT00000520288" 2015   -14741    6585   299966   -8156   309966    -541   308122
 9 "IT00001040286" 2011    -1190    3480     6400    2290     6400       0     4110
 9 "IT00001040286" 2012     -770    3420     5400    2650     5400   -1500     2750
 9 "IT00001040286" 2013     -307    3360     5400    3053     5400       0     2347
 9 "IT00001040286" 2015     -652    3360     5400    2708     5400       .     2692
10 "IT00001360122" 2009    42777    3631   402201   46408   402443    3509   355793
10 "IT00001360122" 2010    41770    5893   403520   47663   408400    1049   355857
10 "IT00001360122" 2011   119096    5387   392889  124483   391759     976   268406
10 "IT00001360122" 2012   -44401    4434   303709  -39967   303831  242585   343676
10 "IT00001360122" 2013    78543    4391   255774   82934   255774     269   172840
10 "IT00001360122" 2014    69758    2146   224270   71904   225059    1240   152366
10 "IT00001360122" 2015    99535    2396   246292  101931   246292   21490   144361
10 "IT00001360122" 2016   112953    2175   266095  115128   266634       .   150967
11 "IT00001400357" 2008    -3881    4867    39522     986    47944   37633    38536
11 "IT00001400357" 2009    32731   37856  1113846   70587  1037611  145490  1043259
11 "IT00001400357" 2010    70918   40748  1340253  111666  1348209  103612  1228587
11 "IT00001400357" 2011    86013   59939  1198768  145952  1238429    1918  1052816
11 "IT00001400357" 2012    70497   71454   751980  141951   750988   13001   610029
11 "IT00001400357" 2013    30197   84908   524771  115105   526860   12341   409666
11 "IT00001400357" 2014   173268   79097   673649  252365   701357     500   421284
11 "IT00001400357" 2015   108066   52918   544573  160984   548729    6417   383589
11 "IT00001400357" 2016   107261   43793   496679  151054   499778       .   345625
12 "IT00001510288" 2007    50017   24878  1330848   74895  1330848  178965  1255953
12 "IT00001510288" 2008    61633   25408  1342931   87041  1342931    9659  1255890
12 "IT00001510288" 2009    54433   27559  1406438   81992  1406457   37487  1324446
12 "IT00001510288" 2010    60898   23247  1543250   84145  1543330   12441  1459105
12 "IT00001510288" 2011    32852   21239  1567760   54091  1567760    1513  1513669
12 "IT00001510288" 2012    19404   18952  1432435   38356  1432875    1370  1394079
12 "IT00001510288" 2013    35653   18592  1332689   54245  1332689    1744  1278444
12 "IT00001510288" 2014    16485   18262  1339473   34747  1339473   -3677  1304726
12 "IT00001510288" 2015    22141    8837  1373913   30978  1374156      -1  1342935
12 "IT00001510288" 2016    -6746    7845  1287539    1099  1293215       .  1286440
13 "IT00001640242" 2007  1048136  309710 15740424 1357846 16025828  748504 14382578
13 "IT00001640242" 2008   416660  361424 14312996  778084 14183567  423310 13534912
13 "IT00001640242" 2009  -125705  415028  8945304  289323  9053252 9740553  8655981
13 "IT00001640242" 2010   -50122 1094642 33666015 1044520 35581574 1662865 32621496
13 "IT00001640242" 2011 -1292385 1869313 41152728  576928 42269631 1065410 40575800
13 "IT00001640242" 2012 -1803093 1718789 35504005  -84304 33881317  633453 35588308
13 "IT00001640242" 2013  -458220 2476003 39705464 2017783 37623867  703897 37687680
13 "IT00001640242" 2014   500902 2148321 35231594 2649223 34807016 1667428 32582372
13 "IT00001640242" 2015   760852 1743511 33791135 2504363 34858254 1202475 31286772
13 "IT00001640242" 2016   968486 1575119 32969794 2543605 32996685       . 30426188
14 "IT00001650282" 2007   735355  362013 16347302 1097368 16379210  948729 15249934
14 "IT00001650282" 2008   256568  394234 14529958  650802 14927982  -76637 13879156
14 "IT00001650282" 2009   676545  499982 16007496 1176527 16493265  -55085 14830969
14 "IT00001650282" 2010   543784  373025 13093373  916809 13980165   -5310 12176564
14 "IT00001650282" 2011   450625  289107 13775652  739732 14323680  201590 13035920
14 "IT00001650282" 2012   825113   58813 15833918  883926 17401237  285055 14949992
14 "IT00001650282" 2013   905085   93290 14648669  998375 15134038   76848 13650294
14 "IT00001650282" 2014  1016517  105236 15616826 1121753 16470623   85909 14495073
14 "IT00001650282" 2015  2003006   74776 17578288 2077782 19413023 -178149 15500506
14 "IT00001650282" 2016  1608077   71349 16958867 1679426 16052036       . 15279441
15 "IT00001900034" 2007    41383    7051    85992   48434    85995 1191948    37558
15 "IT00001900034" 2008   -14179    5990    77467   -8189    77467       1    85656
15 "IT00001900034" 2009    11126   31603    77425   42729    77426       0    34696
15 "IT00001900034" 2010    21476   31603    77467   53079    77468   33979    24388
15 "IT00001900034" 2011    12759   33984    77469   46743    77469       0    30726
15 "IT00001900034" 2012  -150083   34506    74709 -115577    74709       0   190286
15 "IT00001900034" 2013   -34890   34506    12000    -384    12000       .    12384
16 "IT00001930130" 2010   333537   59349  2056156  392886  2050478  110175  1663270
16 "IT00001930130" 2011   433283   78530  2165972  511813  2153374   98784  1654159
16 "IT00001930130" 2012   406497   69349  2079265  475846  2150214   45184  1603419
16 "IT00001930130" 2013   457922   66601  2269885  524523  2222743   57991  1745362
16 "IT00001930130" 2014   552956   53503  2317772  606459  2355443   44529  1711313
16 "IT00001930130" 2015   539650   51111  2414560  590761  2384795   57471  1823799
16 "IT00001930130" 2016   468920   49669  2266194  518589  2268367       .  1747605
17 "IT00001980812" 2007    -8160   15428   381339    7268   391956    6884   374071
17 "IT00001980812" 2008    54926   16831   702306   71757   703564    3014   630549
17 "IT00001980812" 2009    34819   14382   476168   49201   479257       0   426967
17 "IT00001980812" 2010    16467   10355   391791   26822   392441  177554   364969
17 "IT00001980812" 2011      223    8265   307331    8488   307641 -174730   298843
17 "IT00001980812" 2012    45773    9004   508829   54777   509015   30491   454052
17 "IT00001980812" 2013   133050   13324  1013022  146374  1013063    8146   866648
17 "IT00001980812" 2014    36438   14872   536099   51310   536099   19536   484789
17 "IT00001980812" 2015   102954   17714   779261  120668   779261    3254   658593
17 "IT00001980812" 2016    27236   17558   477589   44794   482250       .   432795
end