Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: group classification


From   Jurgen Sidgman <sidgman@uwm.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: group classification
Date   Wed, 26 Jan 2011 16:31:24 -0600

Hi all,

I have what I thought it was a simple problem but has turned out to be a head age. I have a dataset of company names and transaction dates. What I need to do with it is as follows:
For each company, at the end of every april of each year, I want to verify that in the prior six months the company has at least one transaction. If the company has a transaction between november of the prior year and April of the current year I code it with a 1. If the company does not have a transaction within that period, regardless of having transactions in other months (lets say september) I code it with a 0.

I keep getting false positives because I have companies that have transactions in lets' say november and december of last year, no transactions on this year, and again transactions in january of next year. Then, what i get is that i am able to set to one last year and the next year, but I get a zero on the current year, which is not appropriate.

My code follows
. use "dataset.dta", clear
. drop if month(transdate) >= 5 & month(transdate) <= 10
. drop if month(transdate) < 11 & year(transdate) == 2004
. drop if month(transdate) > 4 & year(transdate) == 2008
. save "cross_section.dta", replace
. gen transyear = year(transdate)
. Keep compname transyear
. duplicates drop
. gen prior6 = 1
. snapshot save, label("Snapshot 1")

. use "dataset.dta", clear
. drop if month(transdate) < 11 & year(transdate) == 2004
. drop if month(transdate) > 4 & year(transdate) == 2008
. gen transyear = year(transdate)
. save "cross_section.dta", replace

. merge 1:m cusip form4 transyear using "cross_section.dta"

Obviously merging using the year in the key does not work, but I am out of ideas for the moment. Can anyone help?

Thank you!
*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index