Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: bysort problem


From   "Nikolaos A. Patsopoulos" <npatsop@cc.uoi.gr>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: bysort problem
Date   Mon, 26 Feb 2007 15:22:14 +0200

Jeph Herrin wrote:

I guess I meant, send a revision without the macros, along
with the output, to ensure that it is not a macro assignment
problem. But this does not do what your original code did; there
is the mysterious -var3-, and now you are replacing -var1- instead
of -var2-.

The best way to get help from this list is to provide the simplest
piece of code which produces an error/problem, along with actual
data for which the problem occurs. It is not worth anyone's time
to try guessing whether local E is really assigned to var1, or
whether you really mean -var3- is the same as _id.

cheers,
Jeph


Nikolaos A. Patsopoulos wrote:


All observations are as they appear. No extra decimals. Here is a revision without touse and locals

tempvar _id
qui gen `_id'=0
local _idN=2
while `_idN'!=1 {
bysort var1 var2: replace `_id'=_n'
count if var3>1
replace var1=var1+(`_id'-1)*0.001 if `_id'>1
sum `_id', detail
local _idN=r(max)
list var1 var2 '_id'
}

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


tempvar _id
 qui gen `_id'=0
 local _idN=2
 while `_idN'!=1 {
         bysort var1 var2: replace `_id'=_n
         list var1 var2 `_id'
       count if  `_id'>1
         replace var2=var2+(`_id'-1)*0.001 if `_id'>1
         sum `_id', detail
         local _idN=r(max)
         list var1 var2 `_id'
    }

OUTPUT:

.  tempvar _id

.   qui gen `_id'=0

.   local _idN=2

.   while `_idN'!=1 {
 2.           bysort var1 var2: replace `_id'=_n
 3.           list var1 var2 `_id'
 4.             count if  `_id'>1
 5.           replace var2=var2+(`_id'-1)*0.001 if `_id'>1
 6.           sum `_id', detail
 7.           local _idN=r(max)
 8.           list var1 var2 `_id'
 9.      }
(7 real changes made)

    +------------------------+
    | var1   var2   __000000 |
    |------------------------|
 1. | .145   .014          1 |
 2. | .145   .014          2 |
 3. | .145   .015          1 |
 4. | .167   .015          1 |
 5. | 1.89   .015          1 |
    |------------------------|
 6. | 1.89   .015          2 |
 7. | 1.89   .016          1 |
    +------------------------+
   2
(2 real changes made)

                         __000000
-------------------------------------------------------------
     Percentiles      Smallest
1%            1              1
5%            1              1
10%            1              1       Obs                   7
25%            1              1       Sum of Wgt.           7

50%            1                      Mean           1.285714
                       Largest       Std. Dev.        .48795
75%            2              1
90%            2              1       Variance       .2380952
95%            2              2       Skewness       .9486833
99%            2              2       Kurtosis            1.9

    +------------------------+
    | var1   var2   __000000 |
    |------------------------|
 1. | .145   .014          1 |
 2. | .145   .015          2 |
 3. | .145   .015          1 |
 4. | .167   .015          1 |
 5. | 1.89   .015          1 |
    |------------------------|
 6. | 1.89   .016          2 |
 7. | 1.89   .016          1 |
    +------------------------+
(2 real changes made)

    +------------------------+
    | var1   var2   __000000 |
    |------------------------|
 1. | .145   .014          1 |
 2. | .145   .015          1 |
 3. | .145   .015          1 |
 4. | .167   .015          1 |
 5. | 1.89   .015          1 |
    |------------------------|
 6. | 1.89   .016          1 |
 7. | 1.89   .016          1 |
    +------------------------+
   0
(0 real changes made)

                         __000000
-------------------------------------------------------------
     Percentiles      Smallest
1%            1              1
5%            1              1
10%            1              1       Obs                   7
25%            1              1       Sum of Wgt.           7

50%            1                      Mean                  1
                       Largest       Std. Dev.             0
75%            1              1
90%            1              1       Variance              0
95%            1              1       Skewness              .
99%            1              1       Kurtosis              .

    +------------------------+
    | var1   var2   __000000 |
    |------------------------|
 1. | .145   .014          1 |
 2. | .145   .015          1 |
 3. | .145   .015          1 |
 4. | .167   .015          1 |
 5. | 1.89   .015          1 |
    |------------------------|
 6. | 1.89   .016          1 |
 7. | 1.89   .016          1 |
    +------------------------+

.
.
.
end of do-file

Sorry for the mistakes

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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