Statalist


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

st: AW: AW: Fun with switching point


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: AW: AW: Fun with switching point
Date   Thu, 8 Oct 2009 12:20:06 +0200

<> 



Also look at the techniques provided by Nick in the FAQ:
http://www.stata.com/support/faqs/data/#manip



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Martin Weiss
Gesendet: Donnerstag, 8. Oktober 2009 12:18
An: statalist@hsphsun2.harvard.edu
Betreff: st: AW: Fun with switching point


<> 



*************
clear*

input byte(id x)
1      1
1      1
1      1
1      1
1      0
1      0
1      1
1      1
2      1
end

compress

gen byte y=0
replace y= /* 
*/ cond(x[_n-1]!=x[_n], 0,  /* 
*/ y[_n-1]+1) in 2/l

list, noobs
*************



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Quang Nguyen
Gesendet: Donnerstag, 8. Oktober 2009 11:40
An: statalist@hsphsun2.harvard.edu
Betreff: st: Fun with switching point

Dear all:

Suppose, I have the following data:

id      x
1      1
1      1
1      1
1      1
1      0
1      0
1      1
1      1
2      1
..

Now, I would like to generate a variable _y _such that _y_ takes the
ordering value of 1, 2, 3... as long as the corresponding _x_  takes
the same value as the previous observation. Otherwise,  _y_ is 0.
Specifically, from the above data, we have:

id      x        y
1      1
1      1         1
1      1         2
1      1         3
1      0         0
1      0         1
1      1         0
1      1         1
2      1         2
..

Can you suggest a way to do this in Stata?
--
"My father gave me the greatest gift anyone could give another person,
he believed in me." - Jim Valvano
*
*   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/


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



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