Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SV: st: matrix in mata


From   Mintewab Bezabih <Mintewab.Bezabih@economics.gu.se>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   SV: st: matrix in mata
Date   Fri, 27 Jan 2012 18:17:31 +0100

Thanks Christophe.
here is how my log file looks.
many thanks
minti

      log:  F:\matrix.smcl
  log type:  smcl
 opened on:  27 Jan 2012, 17:11:00

. do "C:\Users\USERAD~1\AppData\Local\Temp\STD11000000.tmp"

. use "f:\nutrition paper\NutrtionElasticityJan25.dta", clear

. mkmat kcal-biotin, matrix(nutrient)

. matrix c = nutrient'

. mkmat income, matrix(i)

. mkmat  ebread- ebeverage, matrix(p)

.
. drop if quarter==.
(10 observations deleted)

. mkmat  share_bread share_biscereal share_milk share_dairy share_meat share_egg share_potato share_fish share_sweet share_veg share_beverage, matrix(share)

. mkmat q_bread - q_beverage, matrix(q)

. matrix s = share'

. matrix quantity = q'

.
end of do-file

. do "C:\Users\USERAD~1\AppData\Local\Temp\STD11000000.tmp"

. matrix e== c*s*q*p

. matrix d=c*s*q

.
end of do-file

. do "C:\Users\USERAD~1\AppData\Local\Temp\STD11000000.tmp"

. mata:
------------------------------------------------- mata (type end to exit) ----------------------------------------------------------------------------------
:   Z = st_matrix("d")

: Z
                  1             2             3             4             5
     +-----------------------------------------------------------------------
   1 |  6.589276565    1.04269975   4.574016508   5.796596303   9.144087441
   2 |  .2776894896   .0439421169   .1927611168   .2442838532   .3853559567
   3 |  .3935476202   .0622757295   .2731852721   .3462044213   .5461348929
   4 |  .5277290114     .08350885    .366328714   .4642439889   .7323414305
   5 |  8.207078725   1.298703864   5.697031108   7.219779247   11.38914792
   6 |  5.864382673   .9279911515   4.070823692   5.158906078   8.138135867
   7 |  2.271196215    .359398441   1.576575042   1.997974656   3.151790121
   8 |  .7880800031   .1247072898   .5470541277   .6932751399   1.093636363
   9 |  3.925448642    .621170515   2.724891983   3.453222954   5.447433458
  10 |  .0378657498   .0059919488   .0262849135   .0333105559   .0525471535
  11 |  .0060061239   .0009504206   .0041692149   .0052835961   .0083348334
  12 |  .0692281637   .0109547973   .0480554672   .0609001176   .0960694814
  13 |  1.814421764   .2871175767   1.259500192   1.596149499   2.517913932
  14 |  12.19989746   1.930535151   8.468688759   10.73226777   16.93007238
  15 |  3.129248276   .4951782434   2.172201019   2.752804319   4.342528284
  16 |  1.940697224   .3070996474   1.347155648   1.707234207    2.69314923
  17 |  .0134078786   .0021216884   .0093072218   .0117949306   .0186064151
  18 |  .0025457174   .0004028392   .0017671368   .0022394713   .0035327493
  19 |  .0044637242   .0007063483   .0030985417   .0039267448   .0061944106
  20 |  .0361796042   .0057251299   .0251144576   .0318272512   .0502072513
  21 |  .0599042069   .0094793565   .0415831433   .0526978191   .0831304166
  22 |  .0699947907   .0110761098   .0485876295   .0615745205    .097133347
  23 |  .0121177733   .0019175397   .0084116814   .0106600231   .0168161069
  24 |  .0026961437   .0004266429   .0018715569   .0023718016   .0037414993
  25 |  .0330006217   .0052220816    .022907733   .0290306955   .0457957057
  26 |  .1465525266   .0231907526   .1017309973   .1289224736   .2033742407
  27 |  .3265630919   .0516759694   .2266872484   .2872780331    .453178955
  28 |  .0116669428   .0018461994   .0080987326   .0102634268   .0161904792
  29 |  .0720635686   .0114034772   .0500236936   .0633944274   .1000042365
     +-----------------------------------------------------------------------
                  6             7             8             9            10
      -----------------------------------------------------------------------
   1    2.222297614    1.38676073   1.670310806   2.649072737   1.472204591
   2    .0936534814   .0584417539   .0703913018   .1116389104   .0620425835
   3    .1327277628   .0828249323   .0997600929   .1582171064   .0879281068
   4    .1779817422   .1110643728   .1337736338   .2121617636    .117907492
   5    2.767917128   1.727238851   2.080406269   3.299474273   1.833660928
   6    1.977820098   1.234201588   1.486557993   2.357645199   1.310245672
   7    .7659830147   .4779896078   .5757238357   .9130841471   .5074404545
   8    .2657876465   .1658571149   .1997698126   .3168301148   .1760762335
   9    1.323895736   .8261389502   .9950590506   1.578139705    .877040667
  10    .0127705924   .0079691199   .0095985607   .0152230862   .0084601291
  11    .0020256237   .0012640321   .0015224879   .0024146291   .0013419141
  12    .0233478716   .0145695659   .0175485956   .0278316503   .0154672549
  13    .6119313883   .3818581335   .4599364207   .7294480936   .4053859366
  14    4.114534084   2.567556323   3.092542915   4.904698632   2.725753712
  15    1.055369418   .6585728464   .7932308132   1.258044979    .699150147
  16    .6545190153   .4084337138   .4919458928    .780214346   .4335989444
  17    .0045219375   .0028217847   .0033987532   .0053903407   .0029956461
  18    .0008585679   .0005357646    .000645312   .0010234493   .0005687752
  19    .0015054344   .0009394229   .0011315061   .0017945415   .0009973045
  20    .0122019234   .0076142584   .0091711409   .0145452088   .0080834032
  21    .0202032765    .012607272   .0151850728   .0240831599   .0133840563
  22     .023606424    .014730908   .0177429273   .0281398557    .015638538
  23    .0040868369   .0025502727   .0030717253   .0048716824   .0027074052
  24    .0009093007   .0005674229   .0006834435   .0010839249   .0006023841
  25    .0111297807   .0069452186    .008365303   .0132671692   .0073731412
  26    .0494262651   .0308430352   .0371494908   .0589181982   .0327433976
  27    .1101365792   .0687275556   .0827802348   .1312874601   .0729621346
  28    .0039347899   .0024553922   .0029574446    .004690436   .0026066787
  29    .0243041394   .0151662972   .0182673403    .028971562   .0161007533
      -----------------------------------------------------------------------
                 11
      ---------------+
   1    2.588498364  |
   2    .1090861466  |
   3    .1545992737  |
   4    .2073104186  |
   5    3.224027652  |
   6    2.303734683  |
   7    .8922053321  |
   8    .3095853966  |
   9     1.54205356  |
  10    .0148749913  |
  11    .0023594156  |
  12    .0271952447  |
  13    .7127683474  |
  14    4.792546542  |
  15    1.229278201  |
  16    .7623737657  |
  17    .0052670838  |
  18    .0010000469  |
  19     .001753507  |
  20    .0142126143  |
  21    .0235324683  |
  22    .0274964026  |
  23    .0047602853  |
  24    .0010591396  |
  25    .0129637988  |
  26    .0575709597  |
  27    .1282854075  |
  28    .0045831833  |
  29    .0283090909  |
      ---------------+

:   Y = st_matrix("e")

:
: Y
                   1              2              3              4              5
     +----------------------------------------------------------------------------
   1 |             .    6.156069061   -.0148428414    1.919848032   -6.140156765
   2 |             .    .2594329831   -.0006255165    .0809074585    -.258762397
   3 |             .    .3676740997   -.0008864956    .1146638204   -.3667237304
   4 |             .    .4930338267   -.0011887493    .1537588374   -.4917594258
   5 |             .    7.667509919   -.0184870625    2.391209989   -7.647690829
   6 |             .    5.478832825   -.0132099633    1.708643343    -5.46467106
   7 |             .    2.121877965   -.0051160404    .6617344925   -2.116393304
   8 |             .    .7362682195   -.0017752095    .2296145606   -.7343651029
   9 |             .    3.667372692   -.0088423685    1.143716579   -3.657893214
  10 |             .    .0353762918   -.0000852955    .0110325442   -.0352848507
  11 |             .    .0056112554   -.0000135292     .001749941   -.0055967513
  12 |             .    .0646768052   -.0001559416    .0201702801   -.0645096276
  13 |             .     1.69513384   -.0040871216    .5286489373   -1.690752234
  14 |             .     11.3978235   -.0274811872    3.554555482   -11.36836225
  15 |             .    2.923517977   -.0070488673    .9117360739   -2.915961226
  16 |             .    1.813107405   -.0043715666    .5654404865   -1.808420859
  17 |             .    .0125263868   -.0000302023    .0039065122   -.0124940084
  18 |             .    .0023783509   -5.73442e-06    .0007417188   -.0023722033
  19 |             .    .0041702597   -.0000100549    .0013005483   -.0041594804
  20 |             .    .0338010008   -.0000814973    .0105412698   -.0337136315
  21 |             .    .0559658456   -.0001349387    .0174536571   -.0558211843
  22 |             .    .0653930308   -.0001576685    .0203936441    -.065224002
  23 |             .    .0113210986   -.0000272962    .0035306278   -.0112918356
  24 |             .    .0025188876   -6.07327e-06     .000785547   -.0025123767
  25 |             .    .0308310183   -.0000743364    .0096150432   -.0307513258
  26 |             .    .1369175305   -.0003301206    .0426994644   -.1365636241
  27 |             .    .3050934237   -.0007356079    .0951472447   -.3043048138
  28 |             .    .0108999076   -.0000262807    .0033992741   -.0108717334
  29 |             .    .0673257983   -.0001623286    .0209964021   -.0671517736
     +----------------------------------------------------------------------------
                   6              7              8              9             10
      ----------------------------------------------------------------------------
   1     1.391563555   -8.173891205    -1.25780323    1.319374858   -6.018957577
   2     .0586441576    -.344469329   -.0530071448    .0556019356   -.2536547436
   3     .0831117832   -.4881894696   -.0751228854    .0788002796   -.3594850523
   4     .1114490266   -.6546393193    -.100736287    .1056675012   -.4820526959
   5     1.733220868   -10.18074867   -1.566619648     1.64330837   -7.496734762
   6     1.238476048   -7.274672035   -1.119430851    1.174228913   -5.356805133
   7     .4796450487   -2.817382239   -.4335404513    .4547630008   -2.074618288
   8     .1664315347   -.9776005215   -.1504337485    .1577977388   -.7198696336
   9     .8290001511    -4.86945567   -.7493147288    .7859949714   -3.585690874
  10     .0079967197   -.0469718513   -.0072280564    .0075818821   -.0345883709
  11     .0012684098   -.0074504998   -.0011464873    .0012026098   -.0054862783
  12     .0146200252   -.0858764195   -.0132147144    .0138615974   -.0632362865
  13     .3831806384   -2.250760907   -.3463484244    .3633027744   -1.657378851
  14     2.576448646   -15.13377585   -2.328794411    2.442792896   -11.14396467
  15     .6608537087   -3.881781969   -.5973309135    .6265712873   -2.858403716
  16      .409848259   -2.407403576   -.3704526913    .3885869866   -1.772724842
  17     .0028315575    -.016632257   -.0025593816    .0026846677   -.0122473919
  18     .0005376201   -.0031579213   -.0004859428    .0005097305   -.0023253789
  19     .0009426765   -.0055371779   -.0008520642    .0008937742   -.0040773773
  20     .0076406292    -.044880215   -.0069061941    .0072442642   -.0330481656
  21     .0126509352   -.0743102016   -.0114348979    .0119946558   -.0547193423
  22     .0147819262   -.0868274079   -.0133610531    .0140150996   -.0639365599
  23     .0025591052   -.0150319022    -.002313118    .0024263491   -.0110689486
  24      .000569388   -.0033445227   -.0005146571    .0005398505   -.0024627855
  25     .0069692723   -.0409367385   -.0062993696    .0066077346   -.0301443323
  26     .0309498551   -.1817960434   -.0279748831    .0293443016   -.1338680251
  27     .0689655826   -.4050962437   -.0623364504    .0653879267   -.2982982088
  28      .002463896   -.0144726542   -.0022270606    .0023360791   -.0106571386
  29     .0152188233   -.0893936934   -.0137559546    .0144293322   -.0658262797
      ----------------------------------------------------------------------------
                  11
      ----------------+
   1    -69.04995187  |
   2    -2.909947049  |
   3    -4.124040624  |
   4    -5.530146213  |
   5    -86.00312726  |
   6    -61.45368727  |
   7    -23.80018319  |
   8    -8.258400713  |
   9    -41.13532603  |
  10    -.3968004946  |
  11    -.0629390135  |
  12    -.7254516219  |
  13    -19.01357975  |
  14    -127.8444339  |
  15    -32.79183089  |
  16    -20.33683798  |
  17    -.1405030379  |
  18    -.0266769289  |
  19    -.0467759913  |
  20    -.3791311393  |
  21    -.6277445731  |
  22    -.7334852139  |
  23    -.1269838437  |
  24    -.0282532674  |
  25    -.3458181362  |
  26     -1.53574445  |
  27    -3.422100372  |
  28    -.1222595275  |
  29    -.7551642265  |
      ----------------+

: X=Y:/Z

:
:   X
                   1              2              3              4              5
     +----------------------------------------------------------------------------
   1 |             .    5.903970976   -.0032450345    .3312026459    -.671489288
   2 |             .    5.903970976   -.0032450345    .3312026459    -.671489288
   3 |             .    5.903970976   -.0032450345    .3312026459    -.671489288
   4 |             .    5.903970976   -.0032450345    .3312026459    -.671489288
   5 |             .    5.903970976   -.0032450345    .3312026459    -.671489288
   6 |             .    5.903970976   -.0032450345    .3312026459    -.671489288
   7 |             .    5.903970976   -.0032450345    .3312026459    -.671489288
   8 |             .    5.903970976   -.0032450345    .3312026459    -.671489288
   9 |             .    5.903970976   -.0032450345    .3312026459    -.671489288
  10 |             .    5.903970976   -.0032450345    .3312026459    -.671489288
  11 |             .    5.903970976   -.0032450345    .3312026459    -.671489288
  12 |             .    5.903970976   -.0032450345    .3312026459    -.671489288
  13 |             .    5.903970976   -.0032450345    .3312026459    -.671489288
  14 |             .    5.903970976   -.0032450345    .3312026459    -.671489288
  15 |             .    5.903970976   -.0032450345    .3312026459    -.671489288
  16 |             .    5.903970976   -.0032450345    .3312026459    -.671489288
  17 |             .    5.903970976   -.0032450345    .3312026459    -.671489288
  18 |             .    5.903970976   -.0032450345    .3312026459    -.671489288
  19 |             .    5.903970976   -.0032450345    .3312026459    -.671489288
  20 |             .    5.903970976   -.0032450345    .3312026459    -.671489288
  21 |             .    5.903970976   -.0032450345    .3312026459    -.671489288
  22 |             .    5.903970976   -.0032450345    .3312026459    -.671489288
  23 |             .    5.903970976   -.0032450345    .3312026459    -.671489288
  24 |             .    5.903970976   -.0032450345    .3312026459    -.671489288
  25 |             .    5.903970976   -.0032450345    .3312026459    -.671489288
  26 |             .    5.903970976   -.0032450345    .3312026459    -.671489288
  27 |             .    5.903970976   -.0032450345    .3312026459    -.671489288
  28 |             .    5.903970976   -.0032450345    .3312026459    -.671489288
  29 |             .    5.903970976   -.0032450345    .3312026459    -.671489288
     +----------------------------------------------------------------------------
                   6              7              8              9             10
      ----------------------------------------------------------------------------
   1     .6261823559    -5.89423325   -.7530354388    .4980515785   -4.088397504
   2     .6261823559    -5.89423325   -.7530354388    .4980515785   -4.088397504
   3     .6261823559    -5.89423325   -.7530354388    .4980515785   -4.088397504
   4     .6261823559    -5.89423325   -.7530354388    .4980515785   -4.088397504
   5     .6261823559    -5.89423325   -.7530354388    .4980515785   -4.088397504
   6     .6261823559    -5.89423325   -.7530354388    .4980515785   -4.088397504
   7     .6261823559    -5.89423325   -.7530354388    .4980515785   -4.088397504
   8     .6261823559    -5.89423325   -.7530354388    .4980515785   -4.088397504
   9     .6261823559    -5.89423325   -.7530354388    .4980515785   -4.088397504
  10     .6261823559    -5.89423325   -.7530354388    .4980515785   -4.088397504
  11     .6261823559    -5.89423325   -.7530354388    .4980515785   -4.088397504
  12     .6261823559    -5.89423325   -.7530354388    .4980515785   -4.088397504
  13     .6261823559    -5.89423325   -.7530354388    .4980515785   -4.088397504
  14     .6261823559    -5.89423325   -.7530354388    .4980515785   -4.088397504
  15     .6261823559    -5.89423325   -.7530354388    .4980515785   -4.088397504
  16     .6261823559    -5.89423325   -.7530354388    .4980515785   -4.088397504
  17     .6261823559    -5.89423325   -.7530354388    .4980515785   -4.088397504
  18     .6261823559    -5.89423325   -.7530354388    .4980515785   -4.088397504
  19     .6261823559    -5.89423325   -.7530354388    .4980515785   -4.088397504
  20     .6261823559    -5.89423325   -.7530354388    .4980515785   -4.088397504
  21     .6261823559    -5.89423325   -.7530354388    .4980515785   -4.088397504
  22     .6261823559    -5.89423325   -.7530354388    .4980515785   -4.088397504
  23     .6261823559    -5.89423325   -.7530354388    .4980515785   -4.088397504
  24     .6261823559    -5.89423325   -.7530354388    .4980515785   -4.088397504
  25     .6261823559    -5.89423325   -.7530354388    .4980515785   -4.088397504
  26     .6261823559    -5.89423325   -.7530354388    .4980515785   -4.088397504
  27     .6261823559    -5.89423325   -.7530354388    .4980515785   -4.088397504
  28     .6261823559    -5.89423325   -.7530354388    .4980515785   -4.088397504
  29     .6261823559    -5.89423325   -.7530354388    .4980515785   -4.088397504
      ----------------------------------------------------------------------------
                  11
      ----------------+
   1    -26.67567916  |
   2    -26.67567916  |
   3    -26.67567916  |
   4    -26.67567916  |
   5    -26.67567916  |
   6    -26.67567916  |
   7    -26.67567916  |
   8    -26.67567916  |
   9    -26.67567916  |
  10    -26.67567916  |
  11    -26.67567916  |
  12    -26.67567916  |
  13    -26.67567916  |
  14    -26.67567916  |
  15    -26.67567916  |
  16    -26.67567916  |
  17    -26.67567916  |
  18    -26.67567916  |
  19    -26.67567916  |
  20    -26.67567916  |
  21    -26.67567916  |
  22    -26.67567916  |
  23    -26.67567916  |
  24    -26.67567916  |
  25    -26.67567916  |
  26    -26.67567916  |
  27    -26.67567916  |
  28    -26.67567916  |
  29    -26.67567916  |
      ----------------+

: end


________________________________________
Fr?n: owner-statalist@hsphsun2.harvard.edu [owner-statalist@hsphsun2.harvard.edu] f&#246;r Christophe Kolodziejczyk [ck.statalist@gmail.com]
Skickat: den 27 januari 2012 15:16
Till: statalist@hsphsun2.harvard.edu
?mne: Re: st: matrix in mata

Can you show us a log file where we can see the matrices Z,Y and X? I
cannot see anything wrong in your code, so I guess it has something to
do with the matrices themselves

Christophe

2012/1/27 Mintewab Bezabih <Mintewab.Bezabih@economics.gu.se>:
> Dear Statalisters,
>
>
> I have done the following mata procedure to do an element by element division in mata.
>
>
> mata:
>  Z = st_matrix("d")
>  Y = st_matrix("e")
> end
> mata:
>  X=Y:/Z
>  X
> end
>
> However the results I get are identical values for each column in x. The figures in X and Y look so different that it is not possible to get identical values. There must be something that I did wrong in the coding. I appreciate it very much if anyone points that out to me
>
> regards
> minti
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index