|
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: re: implementing a pattern to match numbers to ranges
Thank you! (especially Eva and Kit). I really appreciate all your effort. I implemented Kit's version. I guess it is the best way. Thanks!
Silke
Kit Baum schrieb:
< >
To amplify on Eva's posting, say you have the following data on firms:
sic and some measurement var2 (or var2, var3, ...)
+-----------------+
| sic var2 |
|-----------------|
1. | 526 .1369841 |
2. | 3095 .6432207 |
3. | 2092 .5578017 |
4. | 2074 .6047949 |
5. | 4102 .684176 |
|-----------------|
6. | 229 .1086679 |
7. | 2087 .6184582 |
8. | 2096 .0610638 |
9. | 121 .5552388 |
10. | 2048 .8714491 |
+-----------------+
Create a new datafile, concord, that identifies the ranges of SICs
that map into an industry code:
+-------------------+
| sic1 sic2 ind |
|-------------------|
1. | 100 799 3 |
2. | 2048 2048 3 |
3. | 2000 2046 23 |
4. | 2050 2063 23 |
5. | 2070 2079 23 |
6. | 2090 2095 23 |
7. | 2098 2099 23 |
8. | 2064 2068 47 |
9. | 2086 2087 47 |
10. | 2096 2097 47 |
11. | 2080 2085 8 |
+-------------------+
Then use the original file (which might have hundreds or thousands of
obs) and -merge using concord-. This does not match anything; it just
puts sic1, sic2 and ind on the first eleven rows of those new variables.
. g industry=.
(11 missing values generated)
. forv i=1/11 {
2. replace industry = ind[`i'] if inrange(sic, sic1[`i'], sic2[`i'])
3. }
will then use the inrange() function to create the industry codes,
which are left missing if no match is found.
Kit
Kit Baum, Boston College Economics and DIW Berlin
http://ideas.repec.org/e/pba1.html
An Introduction to Modern Econometrics Using Stata:
http://www.stata-press.com/books/imeus.html
*
* 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/