Skip to content

Instantly share code, notes, and snippets.

@iangow
Created February 22, 2016 23:02
Show Gist options
  • Save iangow/a978d39b6aefe4991628 to your computer and use it in GitHub Desktop.
Save iangow/a978d39b6aefe4991628 to your computer and use it in GitHub Desktop.
WITH
sics AS (
SELECT DISTINCT gvkey, sic::integer
FROM comp.company),
obs AS (
SELECT gvkey, datadate, fyear, COALESCE(sich, sic) AS sic, fic
FROM comp.funda
INNER JOIN sics
USING (gvkey)
WHERE indfmt='INDL' AND consol='C' AND popsrc='D' AND datafmt='STD'
AND at > 0 AND sale > 0 AND fic='USA')
SELECT fyear, count(*)
FROM obs
WHERE sic NOT BETWEEN 6000 AND 6999 AND sic NOT BETWEEN 4900 AND 4999 AND sic IS NOT NULL
GROUP BY 1
ORDER BY 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment