[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: RE: Re: local macro with if qualifier |

Date |
Wed, 8 Apr 2009 16:55:07 +0100 |

Thanks for the explanation. You might find the discussion in SJ-9-1 pr0046 . . . . . . . . . . . . . . . . . . . Speaking Stata: > Rowwise (help rowsort, rowranks if installed) . . . . . . . . . . . N > . J. Cox Q1/09 SJ 9(1):137--157 shows how to exploit functions, egen functions, and Mata for working rowwise; rowsort and rowranks are introduced of use or interest, at least for related problems. Nick n.j.cox@durham.ac.uk Sabrina Carrossa My object is to find the best friend among a list of friends. I have a list of "i" occupation (in the db they are 20, in the example just 3). For each occupation in the db I have the variables: - d31b_i : do you have a friend that have the occupation "i"? (yes/no) - d31c_i: how many time do you spend with this person in the occupation "i"? (0/6, with 6 a lot of time) - d31d_i: how do you feel close with this person in the occupation "i"? (0/10, with 10 really close) Than, my idea is that the best friend is a friend with: - d31b_i=1 - d31c_i= max (among each i) - d31d_i=max (among each i) And, if I have more friends with the same value for these three vars, the best friend is the friend with higher occupation (max i) ************************************************ * Stata Code: ************************************************ * compute n vars as sum of the information on d31b d31c d31d and occupation (i) forval i=1/3 { gen d31_`i'=0 replace d31_`i'= (d31b_`i'*100000) + (d31c_`i'*10000) + (d31d_`i'*100) + `i' } * in the first step i assign to friend the value of the friend in the first occupation (i=1) * than i compare the value of this first friend with the values of the other friends * if the values of the other friends are highest (more contact and more closeness) I replace the value of friend gen friend=d31_1 gen f=1 forval y=2/3 { replace f=`y' if confront<d31_`y' replace friend= d31_`y' if confront<d31_`y' } * * 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/

**References**:**st: local macro with if qualifier***From:*Sabrina Carrossa <carrossa@gmail.com>

**st: Re: local macro with if qualifier***From:*"Martin Weiss" <martin.weiss1@gmx.de>

**st: RE: Re: local macro with if qualifier***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**Re: st: RE: Re: local macro with if qualifier***From:*Sabrina Carrossa <carrossa@gmail.com>

- Prev by Date:
**Re: st: RE: Re: local macro with if qualifier** - Next by Date:
**Re: st: spatial weighting matrix** - Previous by thread:
**Re: st: RE: Re: local macro with if qualifier** - Next by thread:
**st: xtpcse and the need for a lagged DV in pooled time-series** - Index(es):

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