From | "����ΰ" <[email protected]> |
To | [email protected] |
Subject | st: =?gb2312?B?c29tZXRoaW5nIG9uIGFkbw==?= |
Date | Fri, 24 Oct 2003 11:20:34 +0800 (CST) |
dear all, For example, now I have the data like this. . set obs 5 . ge x1=1 . ge x2=2 . ge x3=3 . list +--------------+ | x1 x2 x3 | |--------------| 1. | 1 2 3 | 2. | 1 2 3 | 3. | 1 2 3 | 4. | 1 2 3 | 5. | 1 2 3 | +--------------+ I want get each pro! portion . ge prop1=x1/(x1+x2+x3) . ge prop2=x2/(x1+x2+x3) . ge prop3=x3/(x1+x2+x3) . list +--------------------------------------------+ | x1 x2 x3 prop1 prop2 prop3 | |--------------------------------------------| 1. | 1 2 3 .1666667 .3333333 .5 | 2. | 1 2 3 .1666667 .3333333 .5 | 3. | 1 2 3 .166666! 7 .3333333 .5  ;| 4. | 1 2 3 .1666667 .3333333 .5 | 5. | 1 2 3 .1666667 .3333333 .5 | +--------------------------------------------+ In order to make it easy, I wrote the code of ado. But it doesn't work, so I want to know how to do it. Thanks in advance. CUI liwei ***************************** capture program drop prop program define prop syntax [varlist] tokenize "`varlist'" ge sum=0 while "`1'" ~="" {replace sum=sum+`1' mac shift } local i=1 while "`1'" ~="" { ge p`i'=`1'/sum local i=`i'+1 mac shift } end exit ****************************** ============================================================= ������佡��ɱ�����ж��� ������ľ��� ��ס��ľ��� ����ȫ���շѣ� ����վ����������ѧ�������� |
© Copyright 1996–2024 StataCorp LLC | Terms of use | Privacy | Contact us | What's new | Site index |