I don't want to take advantage of your kindness. If it's out of the topic question please pardon me. I applied the same logic to check the correlation between my variables. E.g GDP and export should be positively correlated. I wanted to check whether correlation is in line with the economic intuition (distance and trade-negative, GDP and trade-positive). I modified the code to:
Stata displayed the tables with correlation. However, I see error: invalid syntax. E.g:
The signs are as expected.
However, Stata doesn't display matrix with results for every sector. I see an error:
Here is my output of Stata:
Code:
frame create myresults frame create holding tempfile holding local sectorname xtset id year local where 1 levelsof HSspecific, local(sectors) foreach sector of local sectors{ capture noisily{ di "For sector `sector'" corr log_exp log_GDP log_EXCH log_distance cm_border eu if HSspecific==`sector' mat res= (r(table)[1..6, 1..6])' frame holding{ clear set obs 6 svmat res save `holding', replace } frame myresults{ append using `holding' cap gen sector= "`sector'" in `where' replace sector= "GDP CAP sector `sector'" in `where' local ++where replace sector= "EXCH sector `sector'" in `where' local ++where replace sector= "distance sector `sector'" in `where' local ++where replace sector= "cm_border sector `sector'" in `where' local ++where replace sector= "eu sector `sector'" in `where' local ++where } } } frame myresults{ order sector rename (res1- res6) (log_exp log_GDP log_EXCH log_distance cm_border eu ) } frame drop holding frame myresults: browse frame myresults: l, sep(0)
Code:
invalid syntax For sector 920890 (obs=633) | log_exp log_GDP log_EXCH log_di~e cm_bor~r eu -------------+------------------------------------------------------ log_exp | 1.0000 log_GDP | 0.4240 1.0000 log_EXCH | 0.1270 0.2153 1.0000 log_distance | -0.3936 -0.1605 -0.1713 1.0000 cm_border | 0.4707 0.1857 0.1443 -0.6385 1.0000 eu | 0.0874 0.0537 0.1724 -0.6826 0.3949 1.0000
However, Stata doesn't display matrix with results for every sector. I see an error:
Code:
frame myresults{
. order sector
no variables defined
r(111);
. rename (res1- res6) (log_exp log_GDP log_EXCH log_distance cm_border eu )
. }
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(log_exp log_GDP log_EXCH) long HSspecific float(log_distance cm_border eu) int year float id 21.41338 9.807273 .25675145 0 9.693803 0 0 1991 1 21.630123 9.859335 .13704698 0 9.693803 0 0 1992 1 21.626 9.911574 .1171426 0 9.693803 0 0 1993 1 21.79623 9.97103 .1709818 0 9.693803 0 0 1994 1 22.02459 10.017065 .06047494 0 9.693803 0 0 1995 1 21.972624 10.054852 .1634534 0 9.693803 0 0 1996 1 21.94359 10.10407 .2523011 0 9.693803 0 0 1997 1 21.97477 10.15314 .10024168 0 9.693803 0 0 1998 1 21.960596 10.208075 -.50192624 0 9.693803 0 0 1999 1 21.85747 10.250782 -.4656639 0 9.693803 0 0 2000 1 21.88538 10.294225 -.5490737 0 9.693803 0 0 2001 1 22.030205 10.335284 -.5541078 0 9.693803 0 0 2002 1 22.28353 10.38446 -.55626863 0 9.693803 0 0 2003 1 22.475513 10.432998 -.52555615 0 9.693803 0 0 2004 1 22.55476 10.481292 -.4880296 0 9.693803 0 0 2005 1 22.654886 10.542543 -.51126665 0 9.693803 0 0 2006 1 22.79919 10.588058 -.4933665 0 9.693803 0 0 2007 1 23.000784 10.59926 -.56155837 0 9.693803 0 0 2008 1 22.89651 10.636732 -.58130705 0 9.693803 0 0 2009 1 23.066584 10.664525 -.3682772 0 9.693803 0 0 2010 1 23.173985 10.70166 -.29969665 0 9.693803 0 0 2011 1 23.214634 10.68929 -.2157968 0 9.693803 0 0 2012 1 23.160517 10.773984 -.3189786 0 9.693803 0 0 2013 1 23.06461 10.77067 -.3878373 0 9.693803 0 0 2014 1 . 10.335284 -.5541078 10110 9.693803 0 0 2002 2 . 10.38446 -.55626863 10110 9.693803 0 0 2003 2 . 10.432998 -.52555615 10110 9.693803 0 0 2004 2 . 10.481292 -.4880296 10110 9.693803 0 0 2005 2 8.294049 10.542543 -.51126665 10110 9.693803 0 0 2006 2 . 10.588058 -.4933665 10110 9.693803 0 0 2007 2 10.645425 10.636732 -.58130705 10110 9.693803 0 0 2009 2 . 10.664525 -.3682772 10110 9.693803 0 0 2010 2 . 10.70166 -.29969665 10110 9.693803 0 0 2011 2 10.950807 9.97103 .1709818 10111 9.693803 0 0 1994 3 . 10.054852 .1634534 10111 9.693803 0 0 1996 3 . 10.10407 .2523011 10111 9.693803 0 0 1997 3 . 10.208075 -.50192624 10111 9.693803 0 0 1999 3 . 10.294225 -.5490737 10111 9.693803 0 0 2001 3 10.83958 9.807273 .25675145 10119 9.693803 0 0 1991 4 . 9.859335 .13704698 10119 9.693803 0 0 1992 4 . 9.911574 .1171426 10119 9.693803 0 0 1993 4 . 9.97103 .1709818 10119 9.693803 0 0 1994 4 . 10.017065 .06047494 10119 9.693803 0 0 1995 4 . 10.054852 .1634534 10119 9.693803 0 0 1996 4 . 10.10407 .2523011 10119 9.693803 0 0 1997 4 . 10.15314 .10024168 10119 9.693803 0 0 1998 4 . 10.208075 -.50192624 10119 9.693803 0 0 1999 4 11.066638 10.250782 -.4656639 10119 9.693803 0 0 2000 4 11.198215 10.294225 -.5490737 10119 9.693803 0 0 2001 4 . 10.68929 -.2157968 10121 9.693803 0 0 2012 5 . 10.77067 -.3878373 10121 9.693803 0 0 2014 5 . 10.822786 -.3981192 10121 9.693803 0 0 2016 5 . 10.833665 -.3879531 10121 9.693803 0 0 2017 5 15.227152 10.68929 -.2157968 10129 9.693803 0 0 2012 6 15.211052 10.773984 -.3189786 10129 9.693803 0 0 2013 6 14.995152 10.77067 -.3878373 10129 9.693803 0 0 2014 6 14.288353 10.76284 -.3899194 10129 9.693803 0 0 2015 6 14.704036 10.822786 -.3981192 10129 9.693803 0 0 2016 6 14.532348 10.833665 -.3879531 10129 9.693803 0 0 2017 6 13.927883 10.886076 -.457807 10129 9.693803 0 0 2018 6 10.985292 10.335284 -.5541078 10190 9.693803 0 0 2002 7 12.20106 10.38446 -.55626863 10190 9.693803 0 0 2003 7 10.89674 10.432998 -.52555615 10190 9.693803 0 0 2004 7 14.36767 10.542543 -.51126665 10190 9.693803 0 0 2006 7 13.299672 10.588058 -.4933665 10190 9.693803 0 0 2007 7 14.746887 10.59926 -.56155837 10190 9.693803 0 0 2008 7 15.009736 10.636732 -.58130705 10190 9.693803 0 0 2009 7 14.346915 10.664525 -.3682772 10190 9.693803 0 0 2010 7 14.692664 10.70166 -.29969665 10190 9.693803 0 0 2011 7 6.907755 10.017065 .06047494 10210 9.693803 0 0 1995 8 11.21182 10.588058 -.4933665 10210 9.693803 0 0 2007 8 6.907755 10.15314 .10024168 10310 9.693803 0 0 1998 9 8.798606 10.664525 -.3682772 10511 9.693803 0 0 2010 10 8.699514 9.807273 .25675145 10600 9.693803 0 0 1991 11 8.006368 9.859335 .13704698 10600 9.693803 0 0 1992 11 8.006368 9.911574 .1171426 10600 9.693803 0 0 1993 11 . 9.97103 .1709818 10600 9.693803 0 0 1994 11 . 10.017065 .06047494 10600 9.693803 0 0 1995 11 . 10.054852 .1634534 10600 9.693803 0 0 1996 11 8.149024 10.10407 .2523011 10600 9.693803 0 0 1997 11 8.784315 10.208075 -.50192624 10600 9.693803 0 0 1999 11 . 10.250782 -.4656639 10600 9.693803 0 0 2000 11 9.1049795 10.294225 -.5490737 10600 9.693803 0 0 2001 11 . 10.588058 -.4933665 10611 9.693803 0 0 2007 12 . 10.76284 -.3899194 10613 9.693803 0 0 2015 13 . 10.335284 -.5541078 10619 9.693803 0 0 2002 14 6.907755 10.38446 -.55626863 10619 9.693803 0 0 2003 14 6.907755 10.432998 -.52555615 10619 9.693803 0 0 2004 14 6.907755 10.481292 -.4880296 10619 9.693803 0 0 2005 14 . 10.542543 -.51126665 10619 9.693803 0 0 2006 14 . 10.588058 -.4933665 10619 9.693803 0 0 2007 14 6.907755 10.59926 -.56155837 10619 9.693803 0 0 2008 14 . 10.636732 -.58130705 10619 9.693803 0 0 2009 14 . 10.664525 -.3682772 10619 9.693803 0 0 2010 14 5.627621 10.70166 -.29969665 10619 9.693803 0 0 2011 14 . 10.68929 -.2157968 10619 9.693803 0 0 2012 14 . 10.773984 -.3189786 10619 9.693803 0 0 2013 14 7.487174 10.77067 -.3878373 10619 9.693803 0 0 2014 14 10.28141 10.76284 -.3899194 10619 9.693803 0 0 2015 14 11.195554 10.822786 -.3981192 10619 9.693803 0 0 2016 14 end
Comment