Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Taking the average of observations within a specific date range

    Hi,

    I want to compute the average of a variable (teamsize) for observations within a specific time period. I have a date variable formatted as such that I would like to use. Specifically, I have data on companies and their teams at different points in time. I want to calculate the average team size for a specific company within a given time period, always between the current date and 365 days prior to the observation.


    . bysort company: egen mean(teamsize) if inrange()

    is my best guess (sorry, new to stata and related programs in general!). I do not know how to specify inrange so that it takes the average of all observations with a date (variable is DATE, formatted as %td) in the range of the observation date and the 365 previous days. For example, if the teamsize was 55 on June 1st 2011, I want to create variable with a mean that takes into account all teamsizes from June 1st 2010 to June 1st 2011, including the team size of June 1st 2011.

    It would be awesome if someone could help me out!

    Best,
    Julian

  • #2
    Welcome to Statalist.

    You have accidentally posted your topic in Statalist's Mata Forum, which is used for discussions of Stata's Mata language, which is different than Stata's command language. Your question will see a much larger audience if you post it in Statalist's General Forum.

    Also, if you have not already done so, take a look at the Statalist FAQ linked to at the top of this page for posting guidelines and suggestions.

    Finally, a broader piece of advice. I'm sympathetic to you as a new user of Stata - it's a lot to absorb.

    When I began using Stata in a serious way, I started, as have others here, by reading my way through the Getting Started with Stata manual relevant to my setup. Chapter 18 then gives suggested further reading, much of which is in the Stata User's Guide, and I worked my way through much of that reading as well. There are a lot of examples to copy and paste into Stata's do-file editor to run yourself, and better yet, to experiment with changing the options to see how the results change.

    All of these manuals are included as PDFs in the Stata installation (since version 11) and are accessible from within Stata - for example, through the PDF Documentation section of Stata's Help menu. The objective in doing the reading was not so much to master Stata as to be sure I'd become familiar with a wide variety of important basic techniques, so that when the time came that I needed them, I might recall their existence, if not the full syntax, and know how to find out more about them in the help files and PDF manuals.

    Stata supplies exceptionally good documentation that amply repays the time spent studying it - there's just a lot of it. The path I followed surfaces the things you need to know to get started in a hurry and to work effectively.

    Comment


    • #3
      thanks William, I'm still reading through the stata manuals. I have reposted my question in the general forum.

      Comment

      Working...
      X