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]

From |
"Pavlos C. Symeou" <p.symeou@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Calculating an Index |

Date |
Tue, 24 Jan 2012 16:05:25 +0200 |

Dear Nick,

Best wishes, Pavlos On Δευτέρα, 23 Ιανουάριος 2012 11:51:50 πμ, Nick Cox wrote:

This has the same flavour as the previous problem so you should be able to adapt the previous solutions, or whichever one you adopted. My own view implicit in http://www.stata.com/statalist/archive/2012-01/msg00428.html is that your problem is very awkward without Mata and much lessawkward with it. So, that advice would require you to learn moreaboutMata and I really can't give enough detail in a posting toexplain allthat you need to know. I'd recommend that you study Kit Baum's excellent book http://www.stata.com/bookstore/stata-programming-introductionand William Gould's authoritative columns on Mata matters in theStataJournal in addition to [M]. NickOn Sun, Jan 22, 2012 at 9:05 PM, Pavlos C.Symeou<p.symeou@gmail.com> wrote:Dear Statlisters,Nick and Antonios kindly responded to a similar problem Iencountered lastweek. I hope I can also find some assistance with the followingproblemwhich is a bit more complex. I don't know much about programming(e.g. usingmata) I would appreciate it if you could explain your code sothat I canadjust it in future problems. This way I will avoid to annoy youwithsimilar problems.Here it goes. I have data for a number of firms for multipleyears per firm.Each firm operates in a number of markets each year. A market'sidentifieris denoted by a 3-digit number. I want to calculate a newvariable "index"as follows:1) for each company-year I take the sales_ratio of each marketand multiplyit with each other market's sales ratio:a) If the identifiers of the two markets are the same, then Imultiply theirproduct with 1.b) If the identifiers of the two markets have the same first 2digits (i.e.they differ in the 3rd digit), then I multiply their product with 2.c) If the identifiers of the two markets have the same firstdigit butdiffer in all others, then I multiply their product with 3.d) If the identifiers of the two markets differ in the firstdigit, then Imultiply their product with 4. The "index" variable equals the sum of a, b, c, and d.From the example data below, the Index for Firm 1 in Year 1996should be:(0.071 * 0.14 * 4) + (0.071 * 0.071 * 4) + (0.071 * 0.29 * 4) +(0.14 *0.071 * 3) + (0.14 * 0.29 * 3) +(0.071 * 0.29 * 2) = 0.335 firm_id year market sales_ratio 1 1996 262 .071 1 1996 349 .14 1 1996 353 .071 1 1996 357 .29 1 1997 382 .36 1 1997 733 .071 1 1997 262 .5 1 1997 353 .5 1 1998 349 .15 1 1998 357 .31 1 1998 365 .077 1 1998 382 .38 1 1998 733 .077 2 1996 349 .13 2 1996 357 .27 2 1996 365 .067 2 1996 366 .067 2 1996 371 .067 2 1996 382 .33 2 1996 733 .067* * 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/

* * 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/

**Follow-Ups**:**RE: st: Calculating an Index***From:*Nick Cox <n.j.cox@durham.ac.uk>

**References**:**st: Index***From:*"Pavlos C. Symeou" <p.symeou@gmail.com>

**Re: st: Index***From:*A Loumiotis <antonis.loumiotis@gmail.com>

**st: Calculating an Index***From:*"Pavlos C. Symeou" <p.symeou@gmail.com>

**Re: st: Calculating an Index***From:*Nick Cox <njcoxstata@gmail.com>

- Prev by Date:
**st: RE: cluster analysis** - Next by Date:
**Re: st: ice error** - Previous by thread:
**Re: st: Calculating an Index** - Next by thread:
**RE: st: Calculating an Index** - Index(es):