Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: scrolling over observations

From   "Michael Blasnik" <[email protected]>
To   <[email protected]>
Subject   st: Re: scrolling over observations
Date   Mon, 31 Jan 2005 15:04:17 -0500

Try the encode command. It seems to do exactly what you are trying to do, automatically

encode CoName, gen(conameN)

Michael Blasnik
[email protected]

----- Original Message ----- From: "Dr. J. Clovis, Economics" <[email protected]>
To: <[email protected]>
Sent: Monday, January 31, 2005 2:39 PM
Subject: st: scrolling over observations

Dear listers,

I have been trying to scroll through observations of a variable and assign an identifying code to each occurrence of a key value.

For example, I want to scroll though the variable CoName and give each occurrence of the company BCA, say, the code 4, say. I want to arrange it so that the 1st company (in alpha order) receives code 1 and the last, 680 or whatever is the maximum number of companies in the database.

I have tried the following which gives me a '1' at the start of the occurrence of a new company name and zeros for all other occurrences for that company:

gen new=0
local count =0
bysort CoName: replace new = `count'+1 if CoName[_n] ~= CoName[_n-1]
count = `count'+1

Can anyone say where I'm going wrong. It may help to know that I do not know 'a priori' the number of companies in the dataset or indeed how many times each companies is observed.

I did look at the FAQs on the STATA website but could not understand much of what was said there. Although the for command should help, I can't seem to get it to do the above.

I have been away from this list for a number of years and so protocol may have moved on, so if I am breaching any please excuse my ignorance.

Thanks in advance

Kind regards

J.S. Clovis,

* For searches and help try:
*   For searches and help try:

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