Announcement

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

  • collapse problem

    Sorry this should be simple. I have a dataset that I want to collapse. It is proprietary so I can't post it.

    Here are the commands I entered:

    . fsum party - partyideology income attend - presapp mip* sat* proud democrat - atheistagnostic *imm* leveldissatisfactionimmigration fulllevel
    > satisfactionimmig satimmigration newsat_immig newimmigration_2 newimmigration_2_fs impt_immig

    Variable | N Mean SD Min Max
    ---------------------------------+---------------------------------------------
    party | 226621 3.00 1.67 1.00 5.00
    partyr | 226984 2.01 0.98 1.00 9.00
    partyrr | 226984 2.00 0.83 1.00 9.00
    pres_party | 229264 2.25 2.27 1.00 9.00
    ideology | 221979 2.80 1.03 1.00 5.00
    ideology5 | 226293 2.80 1.02 1.00 5.00
    ideology3 | 226293 1.83 0.77 1.00 3.00
    partyideology | 225934 3.72 1.96 1.00 6.00
    income | 179007 6.40 3.01 1.00 13.00
    attend | 224534 2.97 1.54 1.00 5.00
    attend3 | 224534 2.17 0.86 1.00 3.00
    religiousright | 0
    bornagain | 0
    presapp | 229264 0.59 0.72 0.00 4.00
    mip1 | 229134 29.78 22.00 1.00 96.00
    mip2 | 223677 81.76 29.14 1.00 96.00
    mip3 | 51387 71.04 34.67 1.00 96.00
    mipterrorism | 229264 0.12 0.32 0.00 1.00
    mipecon | 229264 0.32 0.47 0.00 1.00
    mipforeignpolicy | 229264 0.10 0.30 0.00 1.00
    miphealthcare | 229264 0.07 0.25 0.00 1.00
    mipgovt | 229264 0.17 0.38 0.00 1.00
    mipmoral | 229264 0.06 0.23 0.00 1.00
    mip_party | 34184 2.11 0.99 1.00 3.00
    mipfp1 | 23081 9.09 4.96 1.00 23.00
    mipfp2 | 18701 86.68 26.75 1.00 96.00
    mipfp3 | 2031 73.19 38.07 1.00 96.00
    mipwelfare | 228735 1.00 0.03 0.00 1.00
    mipeconomics | 229264 0.00 0.00 0.00 0.00
    satisfyus | 229264 1.69 0.52 1.00 4.00
    satisfyusrecoded | 201653 2.92 1.00 1.00 4.00
    satisfypersonal | 116863 0.91 0.43 0.00 4.00
    satisfypersonalrecoded | 105235 1.58 0.82 1.00 4.00
    sat_qual_life | 228069 1.95 0.79 1.00 4.00
    sat_sys_govt | 224601 2.61 1.00 1.00 4.00
    sat_pwr_govt | 223040 2.83 0.94 1.00 4.00
    sat_moral_clmt | 223236 3.02 0.91 1.00 4.00
    sat_opportunity | 224775 2.15 1.02 1.00 4.00
    sat_corporations | 220554 2.89 0.93 1.00 4.00
    sat_org_relig | 215822 2.43 0.96 1.00 4.00
    sat_distr_wealth | 99412 2.98 1.01 1.00 4.00
    sat_abortion | 200778 2.73 1.02 1.00 4.00
    sat_crime | 216684 2.67 0.90 1.00 4.00
    sat_economy | 220593 2.72 0.93 1.00 4.00
    sat_education | 221525 2.83 0.96 1.00 4.00
    sat_energy | 197015 2.77 0.92 1.00 4.00
    sat_envt | 217505 2.54 0.91 1.00 4.00
    sat_us_role_world | 216645 2.64 0.97 1.00 4.00
    sat_gun_laws | 215491 2.72 1.06 1.00 4.00
    sat_accept_gay | 210169 2.66 0.98 1.00 4.00
    sat_avail_hc | 219813 3.00 0.99 1.00 4.00
    sat_military | 215870 2.04 0.96 1.00 4.00
    sat_poverty | 218965 3.08 0.88 1.00 4.00
    sat_race_rel | 211613 2.69 0.90 1.00 4.00
    sat_taxes | 219272 2.89 0.92 1.00 4.00
    sat_ss_medicare | 214511 2.73 0.99 1.00 4.00
    sat_qual_med | 197527 2.52 1.04 1.00 4.00
    sat_terrorism | 205617 2.40 0.96 1.00 4.00
    sat_govt_surv | 32436 2.92 0.97 1.00 4.00
    sat_camp_fin | 114502 3.08 0.90 1.00 4.00
    sat_pos_min | 162844 2.51 0.91 1.00 4.00
    sat_pos_women | 149417 2.20 0.88 1.00 4.00
    sat_gov_reg_biz | 68829 2.83 0.91 1.00 4.00
    sat_corporations_rec | 185958 2.30 1.06 1.00 4.00
    sat_org_relig_rec | 186704 1.82 1.07 1.00 4.00
    sat_abortion_rec | 200778 1.94 1.04 1.00 4.00
    sat_gun_laws_rec | 197103 1.77 0.89 1.00 4.00
    sat_accept_gay_rec | 229264 5.00 0.00 5.00 5.00
    sat_taxes_rec | 131203 2.34 1.12 1.00 4.00
    sat_gov_reg_biz_rec | 65217 2.44 1.34 1.00 5.00
    satisfiedstate | 61982 1.42 0.54 1.00 4.00
    satisfiedlocalarea | 61982 1.23 0.45 1.00 4.00
    satisfiednow | 98968 2.17 0.82 1.00 5.00
    satisfiedfiveyearsago | 99034 2.40 0.98 1.00 5.00
    satisfiedfiveyearshence | 97564 1.84 0.87 1.00 5.00
    satisfiedhhincome | 7157 2.13 1.19 1.00 5.00
    satisfiedjob | 3769 1.62 0.92 1.00 5.00
    satisfiedstandardliving | 7204 1.99 1.16 1.00 5.00
    satisfiededucation | 7194 1.58 0.90 1.00 5.00
    satisfiedhealth | 7205 1.95 1.13 1.00 5.00
    satisfiedfamilylife | 7197 1.53 0.97 1.00 5.00
    satisfiedcommunity | 7216 1.70 1.03 1.00 5.00
    satisfiedhousing | 7208 1.53 0.99 1.00 5.00
    satisfiedleisuretime | 7191 1.90 1.21 1.00 5.00
    sat_abortiondem | 62708 2.58 1.02 1.00 4.00
    sat_crimedem | 66894 2.66 0.87 1.00 4.00
    sat_org_relig_recdem | 58284 2.01 1.10 1.00 4.00
    sat_abortion_recdem | 62708 1.96 1.12 1.00 4.00
    sat_gun_laws_recdem | 61060 1.84 0.71 1.00 4.00
    sat_accept_gay_recdem | 70707 5.00 0.00 5.00 5.00
    satimmigration | 138326 0.10 0.30 0.00 1.00
    sat_gov_reg_bizdem | 19837 2.80 0.88 1.00 4.00
    sat_gov_reg_bizrep | 19837 2.80 0.88 1.00 4.00
    sat_abortionrep | 91833 2.87 1.00 1.00 4.00
    sat_crimerep | 98129 2.65 0.91 1.00 4.00
    sat_org_relig_recrep | 84265 1.59 0.98 1.00 4.00
    sat_abortion_recrep | 91833 1.91 0.94 1.00 4.00
    sat_gun_laws_recrep | 89265 1.68 0.99 1.00 4.00
    sat_accept_gay_recrep | 103081 5.00 0.00 5.00 5.00
    proud | 50350 1.66 1.03 1.00 7.00
    democrat | 226621 0.31 0.46 0.00 1.00
    republican | 226621 0.45 0.50 0.00 1.00
    independent | 226621 0.09 0.28 0.00 1.00
    liberal | 226293 0.23 0.42 0.00 1.00
    moderate | 226293 0.38 0.48 0.00 1.00
    conservative | 226293 0.40 0.49 0.00 1.00
    protestant | 211577 0.52 0.50 0.00 1.00
    catholic | 211577 0.23 0.42 0.00 1.00
    mormon | 211577 0.02 0.12 0.00 1.00
    otherchristian | 211577 0.01 0.10 0.00 1.00
    jewish | 211577 0.03 0.16 0.00 1.00
    nonchristian | 211577 0.01 0.12 0.00 1.00
    otherrelig | 211577 0.02 0.14 0.00 1.00
    atheistagnostic | 211577 0.13 0.34 0.00 1.00
    overallsatisfactionimmigration | 229264 0.59 0.91 0.00 2.00
    leveldissatisfactionimmigration | 138326 0.10 0.30 0.00 1.00
    fulllevelsatisfactionimmig | 97953 0.08 0.27 0.00 1.00
    finallevelsatisfactionimmig | 229264 0.72 0.96 0.00 2.00
    impt_immig | 229264 0.05 0.22 0.00 1.00
    impt_immigdum | 20995 0.88 0.32 0.00 1.00
    newsat_immig | 128092 2.37 0.63 1.00 3.00
    newimmigration_2 | 138326 2.57 0.67 1.00 3.00
    newimmigration_2_fs | 97953 2.47 0.64 1.00 3.00
    overallimmig | 229264 0.59 0.91 0.00 2.00
    overallimmigdem | 63924 2.79 0.92 1.00 4.00
    satimmigration | 138326 0.10 0.30 0.00 1.00
    overallimmigrep | 229264 0.19 0.58 0.00 2.00
    newsat_immignew | 128092 0.55 0.50 0.00 1.00
    newimmigration_2new | 138326 0.33 0.47 0.00 1.00
    newimmigration_2_fsnew | 97953 0.45 0.50 0.00 1.00
    leveldissatisfactionimmigration | 138326 0.10 0.30 0.00 1.00
    fulllevelsatisfactionimmig | 97953 0.08 0.27 0.00 1.00
    satimmigration | 138326 0.10 0.30 0.00 1.00
    newsat_immig | 128092 2.37 0.63 1.00 3.00
    newimmigration_2 | 138326 2.57 0.67 1.00 3.00
    newimmigration_2_fs | 97953 2.47 0.64 1.00 3.00
    impt_immig | 229264 0.05 0.22 0.00 1.00

    .
    I entered the collapse command with the following Stata response:

    collapse party - partyideology income attend - presapp mip* sat* proud democrat - atheistagnostic *imm* leveldissatisfactionimmigration fulll
    > evelsatisfactionimmig satimmigration newsat_immig newimmigration_2 newimmigration_2_fs impt_immig ,by(state)
    error:
    satimmigration = (mean) satimmigration
    satimmigration = (mean) satimmigration
    name conflict
    r(198);

    Why does this occur when:


    . tab satimmigration

    satimmigrat |
    ion | Freq. Percent Cum.
    ------------+-----------------------------------
    0 | 124,078 89.70 89.70
    1 | 14,248 10.30 100.00
    ------------+-----------------------------------
    Total | 138,326 100.00



    Any help would be appreciated.

    Ric Uslaner

  • #2
    You are asking for the same variable twice over. satimmigration is covered by two wild cards sat* and imm*

    collapse threw you out the first time it spotted the problem, but it will recur.

    Some technique (irrelevant output edited out).

    Code:
    . sysuse auto, clear
    (1978 automobile data)
    
    . ds
    make          mpg           headroom      weight        turn          gear_ratio
    price         rep78         trunk         length        displacement  foreign
    
    . d t* *u*
    
    Variable      Storage   Display    Value
        name         type    format    label      Variable label
    -------------------------------------------------------------------------------------------------------------------------
    trunk           int     %8.0g                 Trunk space (cu. ft.)
    turn            int     %8.0g                 Turn circle (ft.)
    trunk           int     %8.0g                 Trunk space (cu. ft.)
    turn            int     %8.0g                 Turn circle (ft.)
    
    . unab myvars : t* *u*
    
    . mac li
    _myvars:        trunk turn trunk turn
    
    . local myvars : list uniq myvars
    
    . mac li
    _myvars:        trunk turn
    Code:
    
    

    Last edited by Nick Cox; 11 Dec 2024, 08:58.

    Comment


    • #3
      Thanks but now I get:

      . collapse party - partyideology income attend attend3 presapp mipterrorism mipecon mipforeignpolicy miphealthcare mipgovt mipmoral satis
      > fyus - sat_accept_gay_recrep proud democrat - atheistagnostic overallsatisfactionimmigration impt_immig ,by(state)
      error:
      mipterrorism = (mean) mipterrorism
      mipterrorism = (mean) mipterrorism
      name conflict
      r(198);

      .
      . fsum mipterrorism - mipmoral

      Variable | N Mean SD Min Max
      ------------------+---------------------------------------------
      mipterrorism | 229264 0.12 0.32 0.00 1.00
      mipecon | 229264 0.32 0.47 0.00 1.00
      mipforeignpolicy | 229264 0.10 0.30 0.00 1.00
      miphealthcare | 229264 0.07 0.25 0.00 1.00
      mipgovt | 229264 0.17 0.38 0.00 1.00
      mipmoral | 229264 0.06 0.23 0.00 1.00

      .

      Comment


      • #4
        It’s the same problem. You must remove duplicated names from the list of variable names for what you want to do.

        Comment


        • #5
          Sorry to trouble again. I was away and now have:

          des party - partyideology income attend - presapp mip* sat* proud democrat - atheistagnostic *imm* leveldissatisfactionimmigration fulllevels
          > atisfactionimmig newsat_immig newimmigration_2 newimmigration_2_fs impt_immig ,full

          storage display value
          variable name type format label variable label
          ------------------------------------------------------------------------------------------------------------------------------------------------
          party byte %12.0g party Party Affil
          partyr byte %12.0g partyr Party w leaners allocated
          partyrr byte %12.0g partyrr Party-original question
          pres_party byte %12.0g pres_party
          Identify with/Lean to Party of President
          ideology byte %12.0g ideol Ideology: Initial Question
          ideology5 byte %12.0g ideolr R: Ideology - 5 categories - dk into moderate
          ideology3 byte %12.0g ideolrr Ideol - 3 catetories
          partyideology byte %12.0g pidideol Party ID X Ideology
          income byte %12.0g income Income -- Full Categories
          attend byte %12.0g oftnchrc Often attend church
          attend3 byte %12.0g churchat Church Attendance - Three Categories
          religiousright byte %12.0g relright Consider Self Member of Religious Right
          bornagain byte %12.0g bornagn Describe Self as Born-Again or Evangelical
          presapp byte %12.0g presapp Presidential Job Approval
          mip1 byte %12.0g mip1 Most Important Problem: First Mention
          mip2 byte %12.0g mip2 Most Important Problem: Second Mention
          mip3 byte %12.0g mip3 Most Important Problem: Third Mention
          mipterrorism byte %12.0g mipterr Number of Mentions of Terrorism as MIP
          mipecon byte %12.0g mipecon Number of Mentions of Economy as MIP
          mipforeignpolicy
          byte %12.0g mipwar Number of Mentions of War in Iraq/Afghanistan as MIP
          miphealthcare byte %12.0g miphc Number of Mentions of HealthCare as MIP
          mipgovt byte %12.0g mipgovt Number of Mentions of Dissatisfaction with Government as MIP
          mipmoral byte %12.0g mipmoral Numbr of Mentions of Moral/Ethical/Family Decline as MIP
          mip_party byte %12.0g mippartynew
          Party Better Able to Handle Most Important Problem
          mipfp1 byte %12.0g mipfp1 Most Important Family Financial Problem: First Mention
          mipfp2 byte %12.0g mipfp2 Most Important Family Financial Problem: Second Mention
          mipfp3 byte %12.0g mipfp3 Most Important Family Financial Problem: Third Mention
          satisfyus byte %12.0g sat_us Satisfaction with Way Things Going in US
          satisfyusrecoded
          byte %12.0g sat_usr US Satisfaction Recoded
          satisfypersonal byte %12.0g sat_prs Satisfaction with Way Things Going in Personal Life
          satisfypersonalrecoded
          byte %12.0g sat_prsr Personal Satisfaction Recoded
          sat_qual_life byte %12.0g sat_qual_life
          Satisfaction: Overall Quality of Life
          sat_sys_govt byte %12.0g sat_sys_govt
          Satisfaction: System of Goverment
          sat_pwr_govt byte %12.0g sat_pwr_govt
          Satisfaction: Size and Power of Federal Govt
          sat_moral_clmt byte %12.0g sat_moral_clmt
          Satisfaction: Moral and Ethical Climate
          sat_opportunity byte %12.0g sat_opportunity
          Satisfaction: Opportunity for Person to Get Ahead by Working Hard
          sat_corporations
          byte %12.0g sat_corporations
          Satisfaction: Size and Influence of Major Corporations
          sat_org_relig byte %12.0g sat_org_relig
          Satisfaction: Influence of Organized Religion
          sat_distr_wealth
          byte %12.0g sat_distr_wealth
          Satisfaction: Way Income and Wealth are Distributed in the U.S.
          sat_abortion byte %12.0g sat_abortion
          Satisfaction: Policies Regarding Abortion
          sat_crime byte %12.0g sat_crime
          Satisfaction: Policies to Reduce Crime
          sat_economy byte %12.0g sat_economy
          Satisfaction: State of Nations Economy
          sat_education byte %12.0g sat_education
          Satisfaction: Quality of Public Education
          sat_energy byte %12.0g sat_energy
          Satisfaction: Nations Energy Policies
          sat_envt byte %12.0g sat_envt Satisfaction: Quality of the Environment
          sat_us_role_world
          byte %12.0g sat_us_role_world
          Satisfaction: Role America Plays in World Affairs
          sat_gun_laws byte %12.0g sat_gun_laws
          Satisfaction: Nations Laws on Guns
          sat_accept_gay byte %12.0g sat_accept_gay
          Satisfaction: Acceptance of Gays and Lesbians in this Nation
          sat_avail_hc byte %12.0g sat_avail_hc
          Satisfaction: Availability of Affordable Health Care
          sat_military byte %12.0g sat_military
          Satisfaction: Military Strength and Preparedness
          sat_poverty byte %12.0g sat_poverty
          Satisfaction: Efforts to Deal with Poverty and Homelessness
          sat_race_rel byte %12.0g sat_race_rel
          Satisfaction: State of Race Relations
          sat_taxes byte %12.0g sat_taxes
          Satisfaction: Amount Americans Pay in Federal Taxes
          sat_ss_medicare byte %12.0g sat_ss_medicare
          Satisfaction: Social Security and Medicare Systems
          sat_qual_med byte %12.0g sat_qual_med
          Satisfaction: Quality of Medical Care in the Nation
          sat_terrorism byte %12.0g sat_terrorism
          Satisfaction: Nations Security from Terrorism
          sat_govt_surv byte %12.0g sat_govt_surv
          Satisfaction: Govt Surveillance of U.S. Citizens
          sat_camp_fin byte %12.0g sat_camp_fin
          Satisfaction: Campaign Finance Laws
          sat_pos_min byte %12.0g sat_pos_min
          Satisfaction: Positon of Blacks and Other Racial Minorities
          sat_pos_women byte %12.0g sat_pos_women
          Satisfaction: Position of Women in the Nation
          sat_gov_reg_biz byte %12.0g sat_gov_reg_biz
          Satisfaction: Govt Regulation of Businesses and Industries
          sat_corporations_rec
          byte %12.0g sat_corporations_rec
          Recoded Satisfaction with Corporate Power
          sat_org_relig_rec
          byte %12.0g sat_org_relig_rec
          Recoded Satisfaction with Influence of Organized Religion
          sat_abortion_rec
          byte %12.0g sat_abortion_rec
          Recoded Satisfaction with U.S. Abortion Policy
          sat_gun_laws_rec
          byte %12.0g sat_gun_laws_rec
          Recoded Satisfaction with U.S. Gun Policy
          sat_accept_gay_rec
          byte %12.0g sat_accept_gay_rec
          Recoded Satisfaction with Acceptance of Gays and Lesbians in U.S.
          sat_taxes_rec byte %12.0g sat_taxes_rec
          Recoded Satisfaction with Amount Americans Pay in Taxes
          sat_gov_reg_biz_rec
          byte %12.0g sat_gov_reg_biz_rec
          Recoded Satisfaction with Govt Regulation of Businesses and Industries
          satisfiedstate byte %12.0g sat_sta Satisfaction with Way Things Going in Your State
          satisfiedlocalarea
          byte %12.0g sat_loc Satisfaction with Way Things Going in Your Local Community
          satisfiednow byte %12.0g self_lad_now_rec
          Ladder Scale: Personal Situation Now
          satisfiedfiveyearsago
          byte %12.0g self_lad_5yr_ago_rec
          Ladder Scale: Personal Situation Five Years Ago
          satisfiedfiveyearshence
          byte %12.0g self_lad_5yr_now_rec
          Ladder Scale: Personal Situation Five Years from Now
          satisfiedhhincome
          byte %12.0g sat_prs_income
          Satisfaction: Your Household Income
          satisfiedjob byte %12.0g sat_prs_job
          Satisfaction: Your Job or the Work You Do
          satisfiedstandardliving
          byte %12.0g sat_prs_sol
          Satisfaction: Your Standard of Living
          satisfiededucation
          byte %12.0g sat_prs_educ
          Satisfaction: Your Education
          satisfiedhealth byte %12.0g sat_prs_health
          Satisfaction: Your Personal Health
          satisfiedfamilylife
          byte %12.0g sat_prs_family
          Satisfaction: Your Family Life
          satisfiedcommunity
          byte %12.0g sat_prs_community
          Satisfaction: Your Community as a Place to Live
          satisfiedhousing
          byte %12.0g sat_prs_housing
          Satisfaction: Your Current Housing
          satisfiedleisuretime
          byte %12.0g sat_prs_leisure
          Satisfaction: The Amount of Leisure Time You Have
          sat_abortiondem float %9.0g
          sat_crimedem float %9.0g
          sat_org_relig_recdem
          float %9.0g
          sat_abortion_recdem
          float %9.0g
          sat_gun_laws_recdem
          float %9.0g
          sat_accept_gay_recdem
          float %9.0g
          satimmigration float %9.0g
          sat_gov_reg_bizdem
          float %9.0g
          sat_gov_reg_bizrep
          float %9.0g
          sat_abortionrep float %9.0g
          sat_crimerep float %9.0g
          sat_org_relig_recrep
          float %9.0g
          sat_abortion_recrep
          float %9.0g
          sat_gun_laws_recrep
          float %9.0g
          sat_accept_gay_recrep
          float %9.0g
          proud byte %12.0g proud How Proud to Be an American
          democrat byte %8.0g
          republican byte %8.0g
          independent byte %8.0g
          liberal byte %9.0g
          moderate byte %9.0g
          conservative byte %9.0g
          protestant byte %8.0g relpref2==Protestant/Chrisitan (non-specific)
          catholic byte %8.0g relpref2==Catholic
          mormon byte %8.0g relpref2==Mormon
          otherchristian byte %8.0g relpref2==Other specific Christian religion
          jewish byte %8.0g relpref2==Jewish
          nonchristian byte %8.0g relpref2==Other non-Christian religion
          otherrelig byte %8.0g relpref2==Other (unspecified)
          atheistagnostic byte %8.0g relpref2==None/Atheist/Agnostic
          overallsatisfactionimmigration
          byte %12.0g sat_immig
          Satisfaction: Level of Immigration
          leveldissatisfactionimmigration
          byte %12.0g immigration_2
          Level of Immigration in this Country (asked of those dissatisfied)
          fulllevelsatisfactionimmig
          byte %12.0g immigration_2_fs
          Level of Immigration in this Country (Full sample)
          finallevelsatisfactionimmig
          byte %12.0g sat_immig_rec
          Recoded Satisfaction with Level of Immigration Into U.S.
          impt_immig byte %12.0g impt_immig
          Importance for Congress and President to Deal With: Immigration
          impt_immigdum byte %9.0g
          newsat_immig byte %21.0g sat_immig
          Satisfaction: Level of Immigration
          newimmigration_2
          byte %21.0g immigration_2
          Level of Immigration in this Country (asked of those dissatisfied)
          newimmigration_2_fs
          byte %21.0g immigration_2_fs
          Level of Immigration in this Country (Full sample)
          overallimmig float %9.0g
          overallimmigdem float %9.0g
          satimmigration float %9.0g
          overallimmigrep float %9.0g
          leveldissatisfactionimmigration
          byte %12.0g immigration_2
          Level of Immigration in this Country (asked of those dissatisfied)
          fulllevelsatisfactionimmig
          byte %12.0g immigration_2_fs
          Level of Immigration in this Country (Full sample)
          newsat_immig byte %21.0g sat_immig
          Satisfaction: Level of Immigration
          newimmigration_2
          byte %21.0g immigration_2
          Level of Immigration in this Country (asked of those dissatisfied)
          newimmigration_2_fs
          byte %21.0g immigration_2_fs
          Level of Immigration in this Country (Full sample)
          impt_immig byte %12.0g impt_immig
          Importance for Congress and President to Deal With: Immigration

          .Then:

          . collapse party - partyideology income attend - presapp mip* satisfyus - satisfypersonalrecoded sat_qual_life - sat_gov_reg_biz_rec satisfieds
          > tate - satisfiedleisuretime sat_abortiondem - sat_accept_gay_recrep proud democrat - atheistagnostic *imm* overallsatisfactionimmigration le
          > veldissatisfactionimmigration fulllevelsatisfactionimmig satimmigration newsat_immig newimmigration_2 newimmigration_2_fs overallimmig overall
          > immigdem overallimmigrep leveldissatisfactionimmigration fulllevelsatisfactionimmig newsat_immig newimmigration_2 newimmigration_2_fs newimmi
          > gration_2_fs impt_immig ,by(state)
          error:
          overallsatisfactionimmigration = (mean) overallsatisfactionimmigration
          overallsatisfactionimmigration = (mean) overallsatisfactionimmigration
          name conflict

          overallsatisfactionimmigration is there only once. I don't understand what the problem is. Any help would be appreciated.

          Comment


          • #6
            It’s still the same problem. You are duplicating variable names in your call to collapse. The solution provided by Nick can be used to fix it, or else you might be better off to type out each variable name rather than using ranges and wildcards till you have the problem under control.

            Comment


            • #7
              Using a varlist that contains both individual variable names listed by themselves and wildcards that might, potentially, expand to include those same variables, can be difficult, in that reckoning exactly which variables occur in the expansion of the wildcards and matching them to the solo variable names may be tedious and error-prone when done by a person. Moreover, it is a "brittle" solution to the problem: a small change to the data set or the -collapse- command can undo the solution and resurrect the duplicationproblem, or, potentially result in omitting a variable inadvertently. So let Stata resolve it for you automatically:

              Code:
              unab to_collapse: party - partyideology income attend - presapp mip* satisfyus - satisfypersonalrecoded sat_qual_life - sat_gov_reg_biz_rec satisfiedstate - satisfiedleisuretime sat_abortiondem - sat_accept_gay_recrep proud democrat - atheistagnostic *imm* overallsatisfactionimmigration leveldissatisfactionimmigration fulllevelsatisfactionimmig satimmigration newsat_immig newimmigration_2 newimmigration_2_fs overallimmig overallimmigdem overallimmigrep leveldissatisfactionimmigration fulllevelsatisfactionimmig newsat_immig newimmigration_2 newimmigration_2_fs newimmigration_2_fs impt_immig
              
              local to_collapse: list uniq to_collapse
              
              collapse `to_collapse', by(state)
              Last edited by Clyde Schechter; 30 Dec 2024, 12:45.

              Comment


              • #8
                Many thanks. That worked perfectly,

                Comment

                Working...
                X