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]
st: Using a loop to calculate vector differences
From
"Heidi M Pitts" <[email protected]>
To
[email protected]
Subject
st: Using a loop to calculate vector differences
Date
Thu, 20 Sep 2012 15:45:36 -0600
Hi listers,
Can anyone help fix my code for the following issue:
I have two vectors:
M=[0, 0, 0, 0, 0, 0, 0, .1, .4, .4, .1]
F=[0, 0, 0, 0, 0, .05, .3, .6, .05, 0, 0]
so n=11 obs for each vector.
I?m trying to calculate the vector difference between each
element `i? in M and the whole vector F. So the first
vector of differences would be [M1=0 minus
0,0,0,0,0,.05,.3,.6,.05,0,0]. Then I would calculate a
second set of differences, M2=0 - same F vector, and stack
it under the diff vector.
I have written a simple loop to calculate each difference.
But the error message I get is: ?x_male1 not found?.
Seems that my code is not recognizing that I want the
first element of M to subtract each element of F and
populate the vector ?diff?. Can anyone help? Seems that
the first issue is that ?x_male1? is not equal to 0, the
first element in the vector.
/************ program to calculate difference of
distributions***************/
set matsize 100
mkmat x_male
mkmat y_female
mkmat y_fem_inv
set obs 11
gen n=_n
gen diff=.
mkmat diff
forvalues i=1(1)11 {
gen y=x_male`i'-y_female
replace diff=y if `i'< n
}
/*****************************************/
Thanks for any help!
Sincerely,
Heidi M. Pitts
Graduate Student
Department of Economics
University of New Mexico
*
* 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/