Announcement

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

  • Merging data sets

    I have two data sets. One has data on public opinion on an issue over several thousand respondents. There is also a measure indicating the state of residence. I want to merge this data set with another that has how Senators fromj each state voted on thje issue. Is here a straightforward way to merge the roil call data with the public opinion data? Would joinby work? Sorry for this question.

  • #2
    I'm predicating my response on the following interpretation of your question: there is only one issue covered by the public opinion data set, and the Senate data set also contains only votes on that issue, and that the Senate only voted once on this issue. From that, I would infer that in the Senate data set, there are two possibilities, although I cannot distinguish which applies based on your description:
    1. The two Senators from each state appear in the same observation of the data set, i.e. 1 observation per state. OR,
    2. Each Senator appears in his or her own observation in the data set, i.e. 2 observations per state.
    If 1 is a correct description of your data set, then starting with the public opinion data in memory, -merge m:1 state using senate_data_set- (replace italicized parts by the actual names of the variable and data set) should do the job.

    If 2 is a correct description of your dataset, then you can either first -reshape- the senate data set to wide layout so that description 1 applies and then do a -merge m:1- operation, or you can leave the senate data set as is and use -joinby-. Which of those would be better depends on what command you will be using for analysis or further data management of the combined data. It comes down to whether you would be better off with a long data set, which is what -joinby- will give you, or with the wide data set you would have after using -reshape wide- and -merge m:1-.

    If my interpretation of your question is incorrect, or if for some other reason neither 1 nor 2 seems to correctly describe your senate data set, then for further advice you will need to show example data from both data sets. Please use -dataex- to do that.

    Comment

    Working...
    X