Announcement

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

  • Collapse

    Sorry for this post, but I am trying to collapse one data set to merge with another. From the data set I am using to collapse, I typed with the result:

    . xcollapse pid3 - rewardsbased evangelical christiannationalism hispanic christiannationalismfactor - liberal,by(ppstaten) saving(d:\prrinationalismstate.dta)
    error:
    christiannationalism = (mean) christiannationalism
    christiannationalism = (mean) christiannationalism
    name conflict
    r(198);

    but in the dataset christiannationalism is a variable that I should be able to collapse:

    fsum christiannationalism

    Variable | N Mean SD Min Max
    ----------------------+---------------------------------------------
    christiannationalism | 4008 3.06 1.08 1.00 4.00

    And it only appears once.

    What am I doing wrong? Any help would be appreciated,.

    Ric Uslaner

  • #2
    The variable christiannationalism is probably showing up in your varlist specification twice. I suspect it shows up somewhere in the variable range pid3 - rewardsbased or in christiannationalismfactor - liberal. Try removing the explicit reference to christiannationalism in you call to collapse.

    Comment


    • #3
      It is inky there once:

      . des christiannationalism,full

      storage display value
      variable name type format label variable label
      --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      christiannationalism
      byte %8.0g Q42_C * Do you have a favorable or an unfavorable view of each of the following people o

      Comment


      • #4
        My guess is identical to that of Jeff Pitblado (StataCorp) The reason for the error message name conflict is that you are asking twice (or more) for the same output.

        We're limited here by the lack of a data example, and some unexplained details, contrary to longstanding requests in the Statalist FAQ, but the mentions of xcollapse and fsum are probably red herrings for different reasons.

        xcollapse from SSC is probably reacting just as collapse would. I can't test that on RIc/Eric Uslaner's data; it's just a guess,

        The fact that fsum from SSC shows results for just one variable when supplied with just one variable name should not seem surprising and is not germane to the problem.

        Here is how to remove duplicates. I use a silly example in which variable names are repeated.

        Code:
        . sysuse auto, clear
        (1978 automobile data)
        
        . collapse turn trunk t*, by(foreign)
        error:
               turn = (mean) turn
               turn = (mean) turn
        name conflict
        r(198);
        
        . unab myvars : turn trunk t*
        
        . di "`myvars'"
        turn trunk trunk turn
        
        . local myvars : list uniq myvars
        
        . di "`myvars'"
        turn trunk
        So what should work for Eric/Ric is something like


        Code:
        unab myvars : pid3 - rewardsbased evangelical christiannationalism hispanic christiannationalismfactor - liberal
        local myvars : list uniq myvars
        collapse `myvars' ,by(ppstaten) saving(d:\prrinationalismstate.dta)
        Make sure that you run that all at once, not line by line from a do-file editor window.
        Last edited by Nick Cox; 21 Apr 2025, 14:51.

        Comment

        Working...
        X