<>
*************
clear*
input companyname:mylabel companyid /*
*/ str50 date date_s, auto
"Agra and Masterman's ltd" 1 01-03-1965 -1138
"Agra and Masterman's ltd" 1 01-04-1965 -1137
"Agra and Masterman's ltd" 1 01-05-1965 -1136
"Agra and Masterman's ltd" 1 01-06-1965 -1135
"Agra and Masterman's ltd" 1 01-07-1965 -1134
"Agra and Masterman's ltd" 1 01-08-1965 -1133
"Agra and Masterman's ltd" 1 01-09-1965 -1132
"Agra and Masterman's ltd" 1 01-10-1965 -1131
"Agra and United Service ltd" 2 01-03-1959 -1210
"Agra and United Service ltd" 2 01-04-1959 -1209
"Agra and United Service ltd" 2 01-05-1959 -1208
"Agra and United Service ltd" 2 01-06-1959 -1207
"Agra and United Service ltd" 2 01-07-1959 -1206
"Agra and United Service ltd" 2 01-08-1959 -1205
"Agra and United Service ltd" 2 01-09-1959 -1204
"Agra and United Service ltd" 2 01-10-1959 -1203
"Agra and United Service ltd" 2 01-11-1959 -1202
"Agra and United Service ltd" 2 01-12-1959 -1201
"Agra,ltd a" 3 01-04-1967 -1113
"Agra,ltd a" 3 01-05-1967 -1112
"Agra,ltd a" 3 01-06-1967 -1111
"Agra,ltd a" 3 01-07-1967 -1110
"Agra,ltd(do b)" 4 01-02-1968 -1103
"Agra,ltd(do b)" 4 01-03-1968 -1102
"Agra,ltd(do b)" 4 01-04-1968 -1101
"Agra,ltd(do b)" 4 01-05-1968 -1100
"Agra,ltd(do b)" 4 01-06-1968 -1099
"Agra,ltd(do b)" 4 01-07-1968 -1098
"Agra,ltd(do b)" 4 01-08-1968 -1097
"Agra,ltd(do b)" 4 01-09-1968 -1096
"Agra,ltd(do b)" 4 01-10-1968 -1095
"Agra,ltd(do b)" 4 01-11-1968 -1094
"Albion" 5 01-04-1965 -1137
"Albion" 5 01-05-1965 -1136
"Albion" 5 01-06-1965 -1135
end
compress
gen date2=date(date, "DMY")
format date2 %tdMonth_DD,_CCYY
bys companyid (date2): gen variable=/*
*/ _n
list companyname companyid /*
*/ date_s date2 variable, /*
*/ noobs sepby(companyid)
*************
HTH
Martin
-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von 21443017
Gesendet: Dienstag, 4. August 2009 11:56
An: [email protected]
Betreff: 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
Agra,ltd a 3 01-04-1967 -1113 1
Agra,ltd a 3 01-05-1967 -1112 2
Agra,ltd a 3 01-06-1967 -1111 3
Agra,ltd a 3 01-07-1967 -1110 4
Agra,ltd(do b) 4 01-02-1968 -1103 1
Agra,ltd(do b) 4 01-03-1968 -1102 2
Agra,ltd(do b) 4 01-04-1968 -1101 3
Agra,ltd(do b) 4 01-05-1968 -1100 4
Agra,ltd(do b) 4 01-06-1968 -1099 5
Agra,ltd(do b) 4 01-07-1968 -1098 6
Agra,ltd(do b) 4 01-08-1968 -1097 7
Agra,ltd(do b) 4 01-09-1968 -1096 8
Agra,ltd(do b) 4 01-10-1968 -1095 9
Agra,ltd(do b) 4 01-11-1968 -1094 10
Albion 5 01-04-1965 -1137 1
Albion 5 01-05-1965 -1136 2
Albion 5 01-06-1965 -1135 3
?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/
*
* 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/