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

From |
Nirina F <fstata@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: RE: RE: How to generate this variable please? |

Date |
Fri, 23 Oct 2009 13:52:04 -0400 |

Dear Martin, I am getting back to you again because I think we were doing this: Example looking just at category 1 of tenure: say ten1 ten2 ten3 are the percentages of tenure category 1 in year one, then you averaged those 3 percentages which is sum(percentages)/3 How would we do it if we would like to get the percentage this way: sum (frequency of tenure category in each of year 1 2 and 3)/sum (total tenure in each year) Thank you so very much again for your big help. Nirina On Thu, Oct 22, 2009 at 10:27 AM, Martin Weiss <martin.weiss1@gmx.de> wrote: > > <> > > Requires rocket science... > > > ************* > use http://fmwww.bc.edu/ec-p/data/hayashi/griliches76.dta, clear > keep year tenure > > bys ye: gen countyear=_N //how many obs per year? > > levelsof tenure, loc(ten) > foreach lev in `r(levels)'{ //get # for each tenure level > bys year: egen number`lev'=total(tenure==`lev') > } > > foreach lev of local ten{ //get percentages > gen percent`lev'=number`lev'/countyear > } > > drop num* > compress > > tempfile myfile > save `myfile', replace > > //postfile > capture erase info.dta > tempname hdle > postfile `hdle' year /* > */ tenure mean /* > */ using info > > //complete records for 66 thru 71... > forv y=67/70{ > foreach cat of local ten{ > su percent`cat' /* > */ if inrange(year, `y'-1, `y'+1), /* > */ mean > capt assert r(mean)!=. > if !_rc { > post `hdle' (`y') (`cat') (`r(mean)') > } > } > } > > postclose `hdle' > > //see results > u info, clear > gen lb=y-1 > gen ub=y+1 > order lb year ub /* > */ tenure mean > > l, noo sepby(year) h(30) > > //restore to check calculations > u `myfile', clear > ************* > > > > HTH > Martin > > > -----Ursprüngliche Nachricht----- > Von: owner-statalist@hsphsun2.harvard.edu > [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Nirina F > Gesendet: Donnerstag, 22. Oktober 2009 14:01 > An: statalist@hsphsun2.harvard.edu > Betreff: Re: st: RE: RE: How to generate this variable please? > > Dear Martin, > > Thank you very much for your response. > I think we can use this data as an example: > > use http://fmwww.bc.edu/ec-p/data/hayashi/griliches76.dta > > We can use "year"(though there are not that many years here but we can > see the average within -1 and +1 years (instead -3, +3). > then we can consider variable "tenure" to be like "field" in my case. > > So now I would like to attribute for example to year 67 the average > tenure category 1 in percent during the period of 66, 67, and 68. > > Best regards, > Nirina > > > > > On Thu, Oct 22, 2009 at 4:02 AM, Martin Weiss <martin.weiss1@gmx.de> wrote: >> >> <> >> " Now I get confused also with the data you created." >> >> >> That was not my intention. It is always difficult to recreate a dataset > from >> descriptions given on Statalist, so you may want to show an excerpt of > your >> data. Sure, you cannot simply attach it, but you can use -input- to > provide >> a meaningful chunk of your data.... >> >> >> >> HTH >> Martin >> >> -----Ursprüngliche Nachricht----- >> Von: owner-statalist@hsphsun2.harvard.edu >> [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Nirina F >> Gesendet: Donnerstag, 22. Oktober 2009 03:48 >> An: statalist@hsphsun2.harvard.edu >> Betreff: Re: st: RE: RE: How to generate this variable please? >> >> Thank you very much Martin for your response. I might have not been >> clear. I am so sorry. >> The mean that I would like to create is the mean of frequency (in >> percentage actually not in absolute value) of just category 1 to start >> with. >> I am trying to find a data that could be used to make it easier >> because I cannot send files on this list. Now I get confused also with >> the data you created. >> >> >> On Wed, Oct 21, 2009 at 6:16 PM, Martin Weiss <martin.weiss1@gmx.de> > wrote: >>> >>> <> >>> >>> The - forv y=1952/1998- should probably run as - forv y=1953/1997- for a >>> three year window so no window gets "chopped"... >>> >>> >>> HTH >>> Martin >>> >>> >>> -----Original Message----- >>> From: owner-statalist@hsphsun2.harvard.edu >>> [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Martin Weiss >>> Sent: Mittwoch, 21. Oktober 2009 23:52 >>> To: statalist@hsphsun2.harvard.edu >>> Subject: st: RE: How to generate this variable please? >>> >>> >>> <> >>> >>> Try this with no warranty :-) >>> I do have a feeling there is some command, like moving average or >> -rolling-, >>> that can make this a little more elegant... >>> >>> ** >>> clear* >>> set obs 51 >>> >>> gen year=_n+1949 >>> expand 100 >>> >>> gen byte category=irecode(runiform(), /* >>> */ 0, .08, .16, .24, .32, .4, .48, /* >>> */ .54, .62, .68, .78, .89 ) >>> >>> compress >>> >>> capture erase info.dta >>> tempname hdle >>> postfile `hdle' year /* >>> */ category mean /* >>> */ using info >>> >>> levelsof category, local(mycats) >>> >>> qui forv y=1952/1998{ >>> foreach cat of local mycats{ >>> cou if inrange(year, `y'-3, `y'+3) & /* >>> */ category==`cat' >>> post `hdle' (`y') (`cat') (`r(N)') >>> } >>> } >>> >>> postclose `hdle' >>> >>> u info, clear >>> gen lb=y-3 >>> gen ub=y+3 >>> order lb year ub /* >>> */ category mean >>> >>> l, noobs sepby(year) h(30) >>> >>> ** >>> >>> >>> HTH >>> Martin >>> >>> -----Original Message----- >>> From: owner-statalist@hsphsun2.harvard.edu >>> [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nirina F >>> Sent: Mittwoch, 21. Oktober 2009 23:05 >>> To: statalist@hsphsun2.harvard.edu >>> Subject: st: How to generate this variable please? >>> >>> Dear all, >>> >>> I am not even sure how to search in the help for this so I thought I >>> would ask you. >>> >>> I have two variables year (1950 to 2000) and field. Field has >>> different categories 1 for accounting, 2 for art 3 for biochemistry >>> etc....until 12. >>> >>> I would like to have a variable that shows the mean of the frequency >>> in accounting (category 1) for year -3 and +3. To be more explicit: >>> for example, I studied in 1955. I would like to attribute to myself >>> the average frequency of people who did accounting between 1952 and >>> 1958 so that it will be an indicator for me on how popular accounting >>> was around 1955. For year 1950, we can just look at +3, for year 2000, >>> we can just look at -3 years. >>> I am confused myself so I hope you understand what I mean. >>> then I would like to do it for category 5 and 6 together of variable >> Field. >>> >>> Thank you so very much in advance for your help, >>> Nirina >>> * >>> * 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/ >>> >>> * >>> * 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/ >> >> >> * >> * 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/ > > > * > * 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/

**Follow-Ups**:**RE: st: RE: RE: How to generate this variable please?***From:*"Martin Weiss" <martin.weiss1@gmx.de>

**References**:**st: How to generate this variable please?***From:*Nirina F <fstata@gmail.com>

**Re: st: RE: RE: How to generate this variable please?***From:*Nirina F <fstata@gmail.com>

**Re: st: RE: RE: How to generate this variable please?***From:*Nirina F <fstata@gmail.com>

- Prev by Date:
**st: RE: RE: AW: Compute mean for groups leaving one member out** - Next by Date:
**st: FW: Just curious** - Previous by thread:
**Re: st: RE: RE: How to generate this variable please?** - Next by thread:
**RE: st: RE: RE: How to generate this variable please?** - Index(es):

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