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

From |
"Martin Weiss" <martin.weiss1@gmx.de> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: FW: Just curious |

Date |
Fri, 23 Oct 2009 20:12:57 +0200 |

<> Just remove the "+1" in "`y'+1". -inrange()- needs a lower and upper bound to do its magic... I added "lb" and "ub" for your better understanding of the final output, but in the case of the past and current year, the upper bound of course coincides with the current year... HTH Martin -----Original Message----- From: Nirina F [mailto:fstata@gmail.com] Sent: Freitag, 23. Oktober 2009 20:07 To: martin.weiss1@gmx.de Subject: Re: Just curious Dear Martin, When I try the average for the past and current year (-1), the code does not work by just removing the `y'+1 and the ub. I am sure I am not doing it right. Could you please help? Many thanks, Nirina ************* 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 ************* On Thu, Oct 22, 2009 at 7:48 PM, Nirina F <fstata@gmail.com> wrote: > Martin, > Thank you so much for helping out! > I am wondering what do you do for living (put in another way, who is > paying you as you are offering help to statalisters?) > I truly appreciated your 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/

- Prev by Date:
**Re: st: RE: RE: How to generate this variable please?** - Next by Date:
**RE: st: RE: AW: -graph combine- question** - Previous by thread:
**st: outreg2** - Next by thread:
**st: graph interaction in survival analysis** - Index(es):

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