Announcement

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

  • Running a Correlation- one variable with two subsets

    All,
    I'm VERY new at STATA and I've tried searching but nothing seems to give me a correct answer when I try it. I'm also sure this is very basic for many so please forgive me. I'm trying to get the correlation between a few items, with one variable having two subsets.

    Example:

    my league variable as 0, 1 for identifiers (0 is for the American League and 1 for the National League) I have the salary total in millions salarymil, wins, batting, era, hr.

    For the league as a whole I type in
    corr league salarymil wins batting era hr

    Which I get that information as expected, but the trouble I'm having where I keep getting errors is trying to break it out into something like

    corr league_0 league_1 salarymil wins batting era hr

    I get errors, so can anyone just help with the correct commands?

    Thank you in advance.

  • #2
    Well, you don't say what "errors" you are getting. Does the command execute? Are there error messages? If so, what are they? Does it run without error messages but produce results you don't find suitable? If so, what are those results, and what is unsuitable about them?

    Are you looking to do the correlations separately within each league? If so, your approach is not going to get you there. That would be:
    Code:
    by league, sort: orrr salarymil wins batting era hr

    Comment


    • #3
      variable not found. is what I get, with your code i get variable by not found r(111);

      Is the correlation really different across two Leagues.

      Comment


      • #4
        by league, sort: orrr salarymil wins batting era hr
        Well, it appears I mistyped corr as orrr. That's easy enough for you to fix. But that should produce a different error message. So also look at the variables league, salarymil, wins, batting, era, and hr. At least one of those does not actually exist in your data set at the time you are running the command. Perhaps there are typographical errors. Or perhaps somewhere leading up up to that command one or more of them got dropped? This, too, is something you can easily fix yourself.

        Comment

        Working...
        X