Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Follow up on matrix building question -- correct version

From   Kerem Yaman <>
Subject   st: Follow up on matrix building question -- correct version
Date   Fri, 29 Apr 2005 10:10:43 -0700 (PDT)

Sorry My IE is diong strange things. Here is what I
meant to post:

With the help from the list I can now get to the
point where I have a matrix A that looks like this:
      coffee  sugar  wheat
coffee    0     1     0
sugar     1     0     1
wheat     1     0     0

I also have a time series data on coffee, sugar and
wheat. Now I would like to tell stata to cycle through
the variables and do the following:

for each variable I want to build a list of variables
to regress it on using the inputs from the matrix. So
if the cross element A["var", "var(i)] is == 1 then I
need to add var(i) to the list of things var is to be
regressed against.

I have a list of all the variables in a local variable
but not as a list it seems when I display it I get a
concatenated list of the names but I cannot address
them by names(1).

I wanted to do something like:

foreach var of varlist _all{
 local reglist =""
 if A[rownumb(`var', colnumb(`names'(`i'))] == 1 then
add names(`i') to reglist

Then I do my regression var on reglist
and onward to the next var...

How can I address the names in the local variable
names sequentially. It was built by:
levels namesvar, local(names) so holds all the
variable names that the matrix is using to name its
columns and rows. I am looking for some construct like
names(i) names[i] etc.

What is the best reference for me to read to learn
about this type of programming please. I just started
on building a fairly ambitious automated analysis tool
with stata and running into decent amount of
programming issues. I have Hamilton's book already but
it does not have much help on this type of question.

*   For searches and help try:

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