Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • usage of st_view()

    Hi all,

    I am learning mata and my goal is to develop some reading abilities of the mata code. I am following Christopher Baum's book An Introduction to Stata Programming, Second Edition. There is one usage of st_view() that is really puzzling to me in Chapter 14.11. I just pick out the part I don't understand about the usage of st_view(), and the code goes like this
    Code:
    st_view(tt, ., touse) //touse is a scalar select variable, and not every obs is selected
    st_view(eq, .,v) //v is a rowvector containing some variable names in the current dataset
    eq = tt :* eqq
    So the question is, the first use of st_view() does not seem to be documented in the help file. To my understanding, the 3rd argument is a rowvector indicating which variables are included in this view. Or is this argument can be omitted? What is the result of tt?

    Also, suppose everything works fine for the first 2 lines. Since touse does not include every obs, the views, tt and egg do not have the same number of rows. How is the element-wise multiplication possible in the 3rd line?

    By the way, I couldn't find the author in this forum, and it might be a good idea that readers of the same stata book can get together in case anyone has a particular problem.

    Thanks.

  • #2
    Bo Chen I am not able to look into the book, but I don't think there is a problem here. The first view stores all the observations of the Stata variable touse into the mata vector tt. It should be a vector of zeros and ones. The second view stores all the values of the Stata variable v in vector eq. The second argument ensures that we select all the observations of the dataset. These two vectors should therefore have the same number of rows (elements).

    A more typical use of st_view would be

    Code:
    st_view(eq=.,.,v,touse)
    It would select all the observations from v where touse is different from 0.
    Note that the last statement should be rather

    Code:
    eqq = tt :*eq
    Eqq is not defined and if we had instead written eq = eq :* tt, it would have replaced the Stata variable eq where touse is equal to 0, since eq is a view.
    Last edited by Christophe Kolodziejczyk; 23 Jul 2017, 10:21.

    Comment


    • #3
      Originally posted by Christophe Kolodziejczyk View Post
      Bo Chen I am not able to look into the book, but I don't think there is a problem here. The first view stores all the observations of the Stata variable touse into the mata vector tt. It should be a vector of zeros and ones. The second view stores all the values of the Stata variable v in vector eq. The second argument ensures that we select all the observations of the dataset. These two vectors should therefore have the same number of rows (elements).

      A more typical use of st_view would be

      Code:
      st_view(eq=.,.,v,touse)
      It would select all the observations from v where touse is different from 0.
      Note that the last statement should be rather

      Code:
      eqq = tt :*eq
      Eqq is not defined and if we had instead written eq = eq :* tt, it would have replaced the Stata variable eq where touse is equal to 0, since eq is a view.
      Thank you, Christophe. It explains everything. I was so preoccupied with the typical use of st_view(), and thought the argument indicating the columns is missing!

      Comment

      Working...
      X