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]

st: Matching multiple friends to a single respondent using a loop


From   Bobby Jo Otto <[email protected]>
To   [email protected]
Subject   st: Matching multiple friends to a single respondent using a loop
Date   Mon, 22 Jul 2013 14:09:09 -0400

Hello,

I am using version 11.2 for my data analysis and I have a questions.
I have data in which a primary respondent has listed ten friends who
have each been assigned individual ID scores. They  have all answered
questions about their behavior and activities.  I would like to
combine the scores for each of the ten friends to develop a "peer"
score for the primary respondent on the DELINQ variable which is the
sum of the ten friends' scores.

I contacted someone from Stata and they told me to write a loop to
create this variable.  While it worked on my advisor's computer, it
doesn't work on the computer that my data is stored on.  I get an
error message (r(111)) stating that the variable (which is DELINQ) is
not found, although it is an existing variable that has already been
created.  Below is what the data looks and the code I received.

RESPID    FR1ID   FR2ID   FR3ID        DELINQ
1                   7       10         2            .87
2                   5       6          1            .01
3                   8       5          9            .36
4                   3       9          10           .51
5                   4       7          1             .2
6                   9       2          7            .46
7                 10      3           5            .91
8                  1       4           8            .13
9                  6       5           4           .75
10                9       3            7           .62

To Run:

gen DEL_SUM = .
forvalues i=1/`=_N' {

        local f1 = FR1ID[`i']
        local f2 = FR2ID[`i']
        local f3 = FR3ID[`i']

        replace DEL_SUM = DELINQ[`f1'] + DELINQ[`f2'] + DELINQ[`f3'] in `i'

}

list

Again, I'm not sure why this code doesn't work as the variable comes
up as not found.  If anybody can provide assistance, it would be much
appreciated.

Thanks in advance,

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


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