Statalist


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

st: RE: generate a varaible from date


From   Stephen McKay <s.d.mckay@bham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: generate a varaible from date
Date   Tue, 4 Aug 2009 11:05:23 +0100

sort companyid
by companyid: gen variable = _n

presumably, but you'd need to do something different if there are gaps in any sequence ...?


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu on behalf of 21443017
Sent: Tue 04/08/2009 11:00
To: statalist@hsphsun2.harvard.edu
Subject: st: generate a varaible from date
 
Dear All,

How do I generate a variable which equals 1 for the first month the company
enters the dataset, equals 2 for the second month the company enters the
dataset etc...
 
It is an unbalanced panel, so every company starts from a different date.

I have an example of the dataset below,

 
companyname                 companyid        date            
 date_s          variable
Agra and Masterman's ltd           1          01-03-1965        -1138   
       1
Agra and Masterman's ltd           1          01-04-1965        -1137   
       2
Agra and Masterman's ltd           1          01-05-1965        -1136   
       3
Agra and Masterman's ltd           1          01-06-1965        -1135   
       4
Agra and Masterman's ltd           1          01-07-1965        -1134   
       5
Agra and Masterman's ltd           1          01-08-1965        -1133   
       6
Agra and Masterman's ltd           1          01-09-1965        -1132   
       7
Agra and Masterman's ltd           1          01-10-1965        -1131   
       8
Agra and United Service ltd         2          01-03-1959        -1210   
       1
Agra and United Service ltd         2          01-04-1959        -1209   
       2
Agra and United Service ltd         2          01-05-1959        -1208   
       3
Agra and United Service ltd         2          01-06-1959        -1207   
       4
Agra and United Service ltd         2          01-07-1959        -1206   
       5
Agra and United Service ltd         2          01-08-1959       
-1205           6
Agra and United Service ltd         2          01-09-1959        -1204   
       7
Agra and United Service ltd         2          01-10-1959        -1203   
       8
Agra and United Service ltd         2          01-11-1959        -1202   
       9
Agra and United Service ltd         2          01-12-1959        -1201   
      10


"Variable" is the variable that I want to generate from the date.


Many Thanks for your help.


Best Wishes

Wenwen 



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


<<winmail.dat>>




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