Announcement

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

  • mergin datasets



    I have two datasets that wish to merge but cannot find a way to do so. The data set are asss followws with my command to mrge them, but the command didn't wrk:

    First data set:

    p:\Data\Data\ivscum.dta

    oneway ancestry country,tab


    .

    . collapse proudnationality - trustothernationality bornhere respetlaws-immigrantskeepcustoms justifiableillegal justifiableimmoral,by(country)

    . fsum *

    Variable | N Mean SD Min Max
    --------------------------+---------------------------------------------
    country | 49 433.41 273.20 8.00 915.00
    proudnationality | 49 1.67 0.23 1.13 2.12
    trustpeople | 31 2.27 0.29 1.82 3.04
    trustneighborhood | 36 2.04 0.21 1.56 2.53
    trustknowotherpersonally | 36 1.83 0.25 1.21 2.23
    trustfirsttime | 36 2.81 0.33 2.09 3.50
    trustotherreligion | 36 2.46 0.30 1.85 3.05
    trustothernationality | 36 2.44 0.31 1.78 3.07
    bornhere | 47 0.92 0.09 0.55 1.00
    respetlaws | 49 -0.53 1.57 -4.00 1.94
    ancestry | 49 -0.25 1.55 -4.00 2.73
    lang | 49 -0.55 1.52 -4.00 1.93
    immigrantstakejobs | 47 5.32 0.95 3.36 7.46
    immigrantscrime | 47 4.59 0.77 2.87 6.37
    immigrantsstrainwelfare | 47 4.53 0.92 1.87 6.41
    immigrantskeepcustoms | 47 5.58 0.69 3.88 7.07
    justifiableillegal | 13 0.06 0.29 -0.24 0.77
    justifiableimmoral | 13 -0.02 0.28 -0.47 0.35

    . save "p:\Data\Data\ivscum.dta", replace
    file p:\Data\Data\ivscum.dta saved


    second dataset:



    -> oneway immigrantstakejobs country,tab


    my command that didn't work:

    . collapse proudnationality - trustothernationality bornhere respetlaws-immigrantskeepcustoms justifiableillegal justifiableimmoral,by(country)

    . fsum *

    Variable | N Mean SD Min Max
    --------------------------+---------------------------------------------
    country | 49 433.41 273.20 8.00 915.00
    proudnationality | 49 1.67 0.23 1.13 2.12
    trustpeople | 31 2.27 0.29 1.82 3.04
    trustneighborhood | 36 2.04 0.21 1.56 2.53
    trustknowotherpersonally | 36 1.83 0.25 1.21 2.23
    trustfirsttime | 36 2.81 0.33 2.09 3.50
    trustotherreligion | 36 2.46 0.30 1.85 3.05
    trustothernationality | 36 2.44 0.31 1.78 3.07
    bornhere | 47 0.92 0.09 0.55 1.00
    respetlaws | 49 -0.53 1.57 -4.00 1.94
    ancestry | 49 -0.25 1.55 -4.00 2.73
    lang | 49 -0.55 1.52 -4.00 1.93
    immigrantstakejobs | 47 5.32 0.95 3.36 7.46
    immigrantscrime | 47 4.59 0.77 2.87 6.37
    immigrantsstrainwelfare | 47 4.53 0.92 1.87 6.41
    immigrantskeepcustoms | 47 5.58 0.69 3.88 7.07
    justifiableillegal | 13 0.06 0.29 -0.24 0.77
    justifiableimmoral | 13 -0.02 0.28 -0.47 0.35

    p:\icvsnew2026augustnew.dta

    . fsum *

    Variable | N Mean SD Min Max
    ------------------------+---------------------------------------------
    country | 49 433.41 273.20 8.00 915.00
    neighborscriminals | 48 0.53 0.19 0.16 0.83
    priorityimmsjobs | 36 3.62 0.59 2.46 4.72
    unfairjobshandicapped | 49 -3.22 0.79 -4.00 -0.60
    workforsalary | 47 2.47 0.38 1.71 3.16
    lazy | 47 2.28 0.38 1.68 3.60
    equality | 49 -0.15 1.15 -4.00 1.47
    competition | 49 3.05 1.03 -0.88 4.30
    concernY | 46 1.60 0.48 1.08 3.22
    neighbourhood | 47 2.81 0.36 1.67 3.67
    region | 47 2.99 0.33 1.96 3.61
    countrymen | 47 2.91 0.30 1.96 3.43
    europeas | 47 3.44 0.25 2.85 3.95
    humanrace | 47 3.16 0.34 2.25 3.93
    elderly | 47 2.10 0.23 1.55 2.73
    unemployed | 47 2.55 0.37 1.67 3.32
    immigrants | 47 3.23 0.36 2.46 3.99
    disabled | 47 2.18 0.25 1.49 2.76
    taxrich | 49 -1.50 2.08 -4.00 5.64
    interpret | 49 -2.33 1.39 -4.00 2.03
    elecleaders | 49 -0.94 2.61 -4.00 8.88
    unemploymentaid | 49 -1.19 2.42 -4.00 8.09
    churchracedisc | 26 0.68 0.12 0.44 0.88
    churcheuthanasia | 26 0.60 0.13 0.32 0.89
    churchhomosexuality | 26 0.43 0.15 0.22 0.80
    churchecology | 26 0.60 0.11 0.34 0.85
    churchgovernmentpolicy | 26 0.28 0.10 0.15 0.45



    I then typed:

    collapse proudnationality - trustothernationality bornhere respetlaws-immigrantskeepcustoms justifiableillegal justifiableimmoral,by(country)

    . fsum *

    Variable | N Mean SD Min Max
    --------------------------+---------------------------------------------
    country | 49 433.41 273.20 8.00 915.00
    proudnationality | 49 1.67 0.23 1.13 2.12
    trustpeople | 31 2.27 0.29 1.82 3.04
    trustneighborhood | 36 2.04 0.21 1.56 2.53
    trustknowotherpersonally | 36 1.83 0.25 1.21 2.23
    trustfirsttime | 36 2.81 0.33 2.09 3.50
    trustotherreligion | 36 2.46 0.30 1.85 3.05
    trustothernationality | 36 2.44 0.31 1.78 3.07
    bornhere | 47 0.92 0.09 0.55 1.00
    respetlaws | 49 -0.53 1.57 -4.00 1.94
    ancestry | 49 -0.25 1.55 -4.00 2.73
    lang | 49 -0.55 1.52 -4.00 1.93
    immigrantstakejobs | 47 5.32 0.95 3.36 7.46
    immigrantscrime | 47 4.59 0.77 2.87 6.37
    immigrantsstrainwelfare | 47 4.53 0.92 1.87 6.41
    immigrantskeepcustoms | 47 5.58 0.69 3.88 7.07
    justifiableillegal | 13 0.06 0.29 -0.24 0.77
    justifiableimmoral | 13 -0.02 0.28 -0.47 0.35

    . save "p:\Data\Data\ivscum.dta", replace
    file p:\Data\Data\ivscum.dta saved

    and received

    . merge 1:1 proudnationality - justifiableimmoral by(country) using p:\icvsnew2026augustnew.dta
    factor-variable and time-series operators not allowed
    r(101);

    But thee are no factor-variable and time-series operators in either data set, What did I do wrong? Any helpwould be appreciated,

    RiC Uslaner

  • #2
    You have the syntax wrong. -by(country)- is not permitted in -merge-. I think what you actually want is:

    Code:
    merge 1:1 country using p:\icvsnew2026augustnew.dta, keepusing(proudnationality - justifiableimmoral)

    Comment


    • #3
      Euslaner : I see several issues with the commands you are showing us.

      (1) You should always enclose commands and output in code delimiters. Sorry for my harsh words, which are unusual for the Stata Forum: I don’t understand why someone who has been active on the Stata Forum for 12 years with well over 200 posts wouldn’t take the trouble to read the excellent guidelines in the Forum’s FAQ and/or is too lazy (?) to make the minimal effort of using code delimiters for syntax or output to improve readability. If the FAQ isn’t clear enough: You can also ask here how to use code delimiters.

      (2) You are using the command fsum , if you are using community-contributed (also known as user-written) commands, explain that and say where they came from. Again, read the Forum's FAQ.

      (3) You seem to use the dataset "p:\Data\Data\ivscum.dta" but we cannot be sure because you don't show the command reading these data. Please show the commands you are actually using. Again, read the Forum's FAQ.

      (4) I don't understand why you are using the command oneway. If the output is important here, show it (enclosed in code deliminters).

      (5) After collapsing the data (from "p:\Data\Data\ivscum.dta"?) you are using
      Code:
      save "p:\Data\Data\ivscum.dta", replace
      However, this replaces your original data ("p:\Data\Data\ivscum.dta" ?), thus, from this point onward you will not be able to reproduce what you did because the original dataset does not exist anymore.

      (6) You are writing "Second dataset", but after that you are using the same collapse command followed by fsum as before with the same results. Are both datasets identical? How is this possible? If not, why are you repeating the commands?

      (7) Subsequently I see " p:\icvsnew2026augustnew.dta" What does it mean, what did you do, and what did you intend to do with this?

      (8) The third collapse command followed by fsum again shows the same result. Why are you using the same sequence of commands three times?

      (9) As Clyde Schechter already noted, the merge command has a mistake. Read the help for merge using
      Code:
      help merge
      To summarize: Read the Forum's FAQ (especially #12), try to follow the advise given there, create reproducible syntax in Stata's do-file editor, run the commands, tell us what you want to achieve, and show us the commands you actually used (copied from the do-file editor or together with the results from the results window), and ask your question. All in all: Do your part of the task (investigate what you did, summarize it in a form that users of the Forum can read and understand) before expecting that friendly users of the Forum will assist you.

      Comment


      • #4
        Add on:

        To make sense of the seemingly senseless error message "factor-variables and time-series operators not allowed"

        Originally posted by Euslaner View Post
        . merge 1:1 proudnationality - justifiableimmoral by(country) using p:\icvsnew2026augustnew.dta
        factor-variable and time-series operators not allowed
        r(101);

        But thee are no factor-variable and time-series operators in either data set, What did I do wrong? Any helpwould be appreciated,
        This error message will often be produced if Stata, while reading/parsing the command code, is expecting variable names but sees something different. In your case it is " by(country)" which is not preceded by a comma to indicate options. Of course, it still stands that merge has no option by(), which would be another reason for another error message had you used a comma after the last variable name.

        Comment

        Working...
        X