خرید بک لینک

Vote count: 0

I have a panel data set in Stata, which has industry and year dimensions and 7 other variables. I want to split this panel into subpanels by industry-year combination and then use them to calculate new variables using the mahascore from mahapick.ado package. Here is the structure of data sample (numbers for varlist are not real, in my data set they are just some numerical variables):

firm_id  year  ind_id     var1 var2 var3 var4 var5 var6 var 7
1        2008     1         1    2   3    4    5     6   7
1        2009     1         1    2   3    4    5     6   7
1        2010     1         1    2   3    4    5     6   7   
2        2008     2         1    2   3    4    5     6   7
2        2009     2         1    2   3    4    5     6   7
2        2010     2         1    2   3    4    5     6   7

For each of these variables I want to generate 72 new variables (9 industries * 8 years), so that all values for each variable that does not belong to industry-year combination are missing. Than I want to generate 72 varlists, which I will use to calculate mahascore (Mahalanobis distance) separately for each industry-year combination.

The code that I wrote is wrong but I hope it will help to understand what I am doing:

*Generate 72*7 variables:
forvalues i = 2008/2015 {
  forvalues z = 1/9000 {
       gen var1_`i'_`z'=var if year == `i' & ind_id == `z'
       gen var1_`i'_`z'=var if year == `i' & ind_id == `z'
       .....
 }
 }
 *Create 72 varlists
  globale varlist1 var1_2008_1 var1_2008_2 var1_2008_3 var1_2008_4 var5_2008_1 var6_2008_1 var7_2008_1 var8_2008_1
  global metavarlist varlist1 varlist2...varlist72
 *Calculate distance
       foreach v in  $metavarlist {
          mahascore `v', gen(dist_M_`v') refmeans compute

Maybe somebody could improve my logic here.

asked 22 secs ago

برچسب: نویسنده: استخدام کار تاريخ: پنجشنبه 23 ارديبهشت 1395 ساعت: 20:22

صفحه بندی