[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
Matt Dobra <[email protected]> |

To |
[email protected] |

Subject |
Re: st: RE: How can I find the sum of specific values of a variable? |

Date |
Thu, 20 Nov 2003 18:06:29 -0500 |

I think abbrev only works for string variables, which might be a
problem if sic is numeric. A similar approach might be: gen sicabbrev=round(sic-50,100)/100 and from there, do what Adrian suggests de la Garza, Adrian wrote: Why don't you use -abbrev(SIC,2)-? This will abbreviate the values of SIC to only the first 2 characters. You can do this: generate SICabbrev = abbrev(SIC,2) Then you can store the value of all EXPs with SICabbrev = 20 in a variable called 'sum' like this: egen sum = sum(EXP) if SICabbrev == 20 Or you can get the sums by SICabbrev and collapse the dataset like this: collapse (sum) EXP, by(SICabbrev) Hope this helps. Adrian-----Original Message----- From: Delis, A. [mailto:[email protected]] Sent: Thursday, November 20, 2003 4:39 PM To: [email protected] Subject: st: How can I find the sum of specific values of a variable? Dear Statalisters I have a dataset like the following, where the SIC values are in an ascending order SIC EXP 2011 667.8039 2013 130.8002 . . . . 2095 38.90306 2098 0.617763 2111 249.92 2121 3.738577 2131 35.32281 . . . 2298 5.709858 2299 39.7519 . . etc What I want to find is the sum of EXP values that have a SIC value begining with 20, i.e. 667.8039+130.8002+..+38.90306+0.617763 In others words I have some 4digit SIC data and I want to aggregate them into 2digit SIC. Any hint is really appreciated * * 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/ |

**References**:**st: RE: How can I find the sum of specific values of a variable?***From:*"de la Garza, Adrian" <[email protected]>

- Prev by Date:
**Re: st: How can I find the sum of specific values of a variable?** - Next by Date:
**st: Re: How can I find the sum of specific values of a variable?** - Previous by thread:
**st: RE: How can I find the sum of specific values of a variable?** - Index(es):

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