Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Mata


From   "Jeper K. Hansen" <[email protected]>
To   [email protected]
Subject   Re: st: Mata
Date   Wed, 23 Jan 2008 00:33:54 +0100

A view is what is says: a view.

When you -insheet- data the second time, F is updated, and you get F
== A. Is this the "problem" you are refering to? Maybe in this case
you need -st_data()- instead of -st_view()?

An example is attached below.

/Jesper


Example:
-------------------begin-------------------
. mata
--- mata (type end to exit) ---
: mata clear

: stata("insheet using test.txt, clear")
(3 vars, 10 obs)

: st_view(F=.,.,.)

: F
            1       2       3
     +-------------------------+
   1 |   4099      22       3  |
   2 |   4749      17       3  |
   3 |   3799      22       .  |
   4 |   4816      20       3  |
   5 |   7827      15       4  |
   6 |   5788      18       3  |
   7 |   4453      26       .  |
   8 |   5189      20       3  |
   9 |  10372      16       3  |
  10 |   4082      19       3  |
     +-------------------------+

: stata("insheet using test2.txt, clear")
(3 vars, 10 obs)

: st_view(A=.,.,.)

: A
           1      2      3
     +----------------------+
   1 |    11   2930    186  |
   2 |    11   3350    173  |
   3 |    12   2640    168  |
   4 |    16   3250    196  |
   5 |    20   4080    222  |
   6 |    21   3670    218  |
   7 |    10   2230    170  |
   8 |    16   3280    200  |
   9 |    17   3880    207  |
  10 |    13   3400    200  |
     +----------------------+

: F
           1      2      3
     +----------------------+
   1 |    11   2930    186  |
   2 |    11   3350    173  |
   3 |    12   2640    168  |
   4 |    16   3250    196  |
   5 |    20   4080    222  |
   6 |    21   3670    218  |
   7 |    10   2230    170  |
   8 |    16   3280    200  |
   9 |    17   3880    207  |
  10 |    13   3400    200  |
     +----------------------+

:
-------------------end---------------------


On Jan 22, 2008 11:38 PM, Raphael Fraser <[email protected]> wrote:
> Can anyone explain why the matrix X gives the incorrect result?
> When I run the code and check the contents of the matrix A and F.
> A is the matrix view of amt.csv but A is also the view of the same file.
> At some point the matrix F becomes A. What's the problem?
>
> ***begin here***
> mata clear
> stata("insheet using freq.csv, clear")
> stata("drop subjectid")
> st_view(F=., ., .)                            /* 91 subjects x 110 foods */
>
> stata("insheet using amt.csv, clear")
> stata("drop subjectid")
> st_view(A=., ., .)                           /* 91 subjects x 110 foods */
> X = 0.01*(A:*F)
> ***end here***
>
> Raphael
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index