Statalist The Stata Listserver


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

Re: st: How to construct a duration variable?


From   Robert A Yaffee <bob.yaffee@nyu.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: How to construct a duration variable?
Date   Thu, 06 Apr 2006 13:45:36 -0400

Albert,
  Have you tsset your week?  Are the last two observations of week
correctly 964?   
  Suppose you have tsset your week.
tsset week

You could try constructing 
a temporary working variable (twv):

 gen twv=1
 gen cntr1 = sum(twv) if switch==l.switch & hhid == l.hhid
 recode cntr1(.=0)

Then cntr1 would be a counter for the time the switch equals
1.
  Regards,
  - RY


Robert A. Yaffee, Ph.D.
Research Professor
Shirley M. Ehrenkranz
School of Social Work
New York University

home address:
Apt 19-W
2100 Linwood Ave.
Fort Lee, NJ
07024-3171
Phone: 201-242-3824
Fax: 201-242-3825
yaffee@nyu.edu

----- Original Message -----
From: Albert Newton <lacneo@gmail.com>
Date: Thursday, April 6, 2006 12:51 pm
Subject: st: How to construct a duration variable?

> Dear Statalist users,
>       I get stuck in coding a during variable.  The data is like:
> 
> hhid    weekshoppingday triptype        switch  switchtype      
> Duration1871877 954     7       1       0       0       0
> 1871877 955     7       2       1       2       1
> 1871877 956     3       1       1       4       1
> 1871877 957     6       0       1       1       1
> 1871877 958     7       1       1       6       3
> 1871877 959     7       1       0       0       0
> 1871877 960     7       1       0       0       0
> 1871877 961     7       0       1       1       1
> 1871877 962     7       2       1       5       1
> 1871877 963     4       1       1       4       3
> 1871877 964     2       1       0       0       0
> 1871877 964     7       1       0       0       0
> 
> I just wanto count how long the customer stay in the switched shopping
> type.  Could any one give some suggestion of how to constuct the
> variable "Duration"?
> The one above is make manually.
> 
> Thanks a lot!
> 
> Albert
> 
> *
> *   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/



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