Announcement

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

  • merge two a longer data date form in a shorter one

    i have two data sets one is recording the transaction from Mon to Sun (7days a week) during 2010~2018,
    the other one is recording in weekdays (5 days a week) dring 2010~2018,

    how should I be able to merge these two data in date? i want to drop the data which is recorded on weekends, but my variable "date" is recorded in dd/mm/yyyy
    can someone help me out with this?

    Click image for larger version

Name:	statahelp.png
Views:	1
Size:	23.6 KB
ID:	1454823

  • #2
    Welcome to Statalist.

    Stata's "date and time" variables are complicated and there is a lot to learn. If you have not already read the very detailed Chapter 24 (Working with dates and times) of the Stata User's Guide PDF, do so now. If you have, it's time for a refresher. After that, the help datetime documentation will usually be enough to point the way. You can't remember everything; even the most experienced users end up referring to the help datetime documentation or back to the manual for details. But at least you will get a good understanding of the basics and the underlying principles. An investment of time that will be amply repaid.

    All Stata 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.

    Once you understand how date and time variables are meant to be handled in Stata, you will want to follow the instructions for converting your string date variable to a SIF daily date variable. Do this in both datasets, and you should have no trouble merging the datasets. Once merged, you can drop the observations that do not appear in both datasets, using the _merge variable as discussed in the output of help merge.

    Some further advice to improve subsequent posts. Please review the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post. Note especially sections 9-12 on how to best pose your question.

    Please be sure to use the dataex command to show example data. If you are running version 15.1 or a fully updated version 14.2, it is already part of your official Stata installation. If not, run ssc install dataex to get it. Either way, run help dataex and read the simple instructions for using it. dataex will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    The more you help others understand your problem, the more likely others are to be able to help you solve your problem.

    Comment

    Working...
    X