From | "Michael Blasnik" <[email protected]> |
To | <[email protected]> |
Subject | st: Re: scrolling over observations |
Date | Mon, 31 Jan 2005 15:04:17 -0500 |
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:
* 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–2024 StataCorp LLC | Terms of use | Privacy | Contact us | What's new | Site index |