Announcement

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

  • entering data

    Help pleaw qith entering data

    Here is what I have si far, I need to enter country names in the 2n column but ever name I enter comes in the last column. How do I get the remaining countries in th 2nd column, pleae. (I tried to enter the ames by dataexn but it didn't work.) Any help would be appreciated.

    Ric Uslaner

    Valid 8 Albania | 2969 1.32 1.32 1.32
    31 Azerbaijan | 1800 0.80 0.80 2.12
    40 Austria | 6136 2.73 2.73 4.86
    51 Armenia | 3000 1.34 1.34 6.20
    56 Belgium | 7358 3.28 3.28 9.47
    70 Bosnia and Herzegovina | 3236 1.44 1.44 10.92
    100 Bulgaria | 5092 2.27 2.27 13.18
    112 Belarus | 4048 1.80 1.80 14.99
    124 Canada | 2984 1.33 1.33 16.32
    191 Croatia | 4015 1.79 1.79 18.11
    196 Cyprus | 1000 0.45 0.45 18.55
    197 Northern Cyprus | 500 0.22 0.22 18.78
    203 Czech Republic | 7649 3.41 3.41 22.18
    208 Denmark | 8104 3.61 3.61 25.79
    233 Estonia | 4835 2.15 2.15 27.95
    246 Finland | 3959 1.76 1.76 29.71
    250 France | 7188 3.20 3.20 32.92
    268 Georgia | 3694 1.65 1.65 34.56
    276 Germany | 11023 4.91 4.91 39.47





    528 Netherlands | 7199 3.21 3.21 63.21
    578 Norway | 4502 2.01 2.01 65.22
    616 Poland | 4939 2.20 2.20 67.42
    620 Portugal | 4953 2.21 2.21 69.62
    642 Romania | 5351 2.38 2.38 72.01
    643 Russia | 5829 2.60 2.60 74.61
    688 Serbia | 3011 1.34 1.34 75.95
    703 Slovakia | 5408 2.41 2.41 78.36
    705 Slovenia | 4482 2.00 2.00 80.35
    724 Spain | 8849 3.94 3.94 84.30
    752 Sweden | 5397 2.40 2.40 86.70
    756 Switzerland | 4445 1.98 1.98 88.68
    792 Turkey | 3590 1.60 1.60 90.28


  • #2
    Euslaner:
    limiting my example to the first nation, you may want to consider something along the following lines:
    Code:
    input Valid str20 Country First_var Second_var Third_var Fourth_var
    8 Albania 2969 1.32 1.32 1.32
    end
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Carlo Lazzaro is guessing that you (meaning Eric or Ric Uslaner) are or should be using input. If that is so, then country names with spaces need quotation marks around them.

      Now Carlo is usually right about Stata, but he is guessing given that #1 really doesn't explain anything much beyond that entering data is proving problematic.

      Here are my guesses.

      The word Valid -- as Carlo also implies -- is quite out of place. So I zapped that.

      I copied and pasted some data as sample text into the Data Editor.

      Code:
      . l var1
      
           +--------------------------------------------------+
           |                                             var1 |
           |--------------------------------------------------|
        1. |                  8 Albania | 2969 1.32 1.32 1.32 |
        2. |              31 Azerbaijan | 1800 0.80 0.80 2.12 |
        3. |                 40 Austria | 6136 2.73 2.73 4.86 |
        4. |                 51 Armenia | 3000 1.34 1.34 6.20 |
        5. |                 56 Belgium | 7358 3.28 3.28 9.47 |
           |--------------------------------------------------|
        6. | 70 Bosnia and Herzegovina | 3236 1.44 1.44 10.92 |
        7. |              100 Bulgaria | 5092 2.27 2.27 13.18 |
        8. |               112 Belarus | 4048 1.80 1.80 14.99 |
        9. |                124 Canada | 2984 1.33 1.33 16.32 |
       10. |               191 Croatia | 4015 1.79 1.79 18.11 |
           |--------------------------------------------------|
       11. |                196 Cyprus | 1000 0.45 0.45 18.55 |
       12. |        197 Northern Cyprus | 500 0.22 0.22 18.78 |
       13. |        203 Czech Republic | 7649 3.41 3.41 22.18 |
       14. |               208 Denmark | 8104 3.61 3.61 25.79 |
       15. |               233 Estonia | 4835 2.15 2.15 27.95 |
           |--------------------------------------------------|
       16. |               246 Finland | 3959 1.76 1.76 29.71 |
       17. |                250 France | 7188 3.20 3.20 32.92 |
       18. |               268 Georgia | 3694 1.65 1.65 34.56 |
       19. |              276 Germany | 11023 4.91 4.91 39.47 |
           +--------------------------------------------------+
      My first detail to cope with is the bars that follow country names.

      Code:
      . split var1, parse(|)
      variables created as string:
      var11  var12
      Then I want to move the first word (which is a number for the researcher but a word in a string variable for Stata) into a separate variable:

      Code:
      . gen valid = real(word(var1, 1))
      Now I can get at the country names:

      Code:
      . gen country = trim(subinstr(var11, word(var11, 1), "", .))



      Now I work at what followed the | which looks like a bundle of numeric variables.


      Code:
      . split var12, destring
      variables born as string:
      var121  var122  var123  var124
      var121: all characters numeric; replaced as int
      var122: all characters numeric; replaced as double
      var123: all characters numeric; replaced as double
      var124: all characters numeric; replaced as double

      Code:
      . drop var11 var12
      
      . l
      
           +--------------------------------------------------------------------+
           | valid                  country   var121   var122   var123   var124 |
           |--------------------------------------------------------------------|
        1. |     8                  Albania     2969     1.32     1.32     1.32 |
        2. |    31               Azerbaijan     1800       .8       .8     2.12 |
        3. |    40                  Austria     6136     2.73     2.73     4.86 |
        4. |    51                  Armenia     3000     1.34     1.34      6.2 |
        5. |    56                  Belgium     7358     3.28     3.28     9.47 |
           |--------------------------------------------------------------------|
        6. |    70   Bosnia and Herzegovina     3236     1.44     1.44    10.92 |
        7. |   100                 Bulgaria     5092     2.27     2.27    13.18 |
        8. |   112                  Belarus     4048      1.8      1.8    14.99 |
        9. |   124                   Canada     2984     1.33     1.33    16.32 |
       10. |   191                  Croatia     4015     1.79     1.79    18.11 |
           |--------------------------------------------------------------------|
       11. |   196                   Cyprus     1000      .45      .45    18.55 |
       12. |   197          Northern Cyprus      500      .22      .22    18.78 |
       13. |   203           Czech Republic     7649     3.41     3.41    22.18 |
       14. |   208                  Denmark     8104     3.61     3.61    25.79 |
       15. |   233                  Estonia     4835     2.15     2.15    27.95 |
           |--------------------------------------------------------------------|
       16. |   246                  Finland     3959     1.76     1.76    29.71 |
       17. |   250                   France     7188      3.2      3.2    32.92 |
       18. |   268                  Georgia     3694     1.65     1.65    34.56 |
       19. |   276                  Germany    11023     4.91     4.91    39.47 |
           +--------------------------------------------------------------------+
      So what are the messages?

      You need to know some basic management commands such as split and destring.

      You need to know some basic string functions.

      I used many little applications of list to see where I had got to.

      Now as an example of data management my code is in one sense appalling. Many people wouldn't dream of starting with copy and paste. What does "the researcher did a copy and paste at this point" mean in terms of an audit trail that is reproducible? But I am working from the information in #1.

      If I was doing this again, I could do it a little more simply.

      A deeper point is that you (Eric or RIc) did something that was at best not quite right and asked us to bail you out. This was an example of the X-Y problem. You wanted us to fix a solution that hadn't worked well. It would be better to tell us about the data source and ask how to read it into Stata. It's probably something like an Excel-readable file, but once again we have to guess in the absence of hard information. If that is true,

      Code:
      db import excel
      and

      Code:
      db import delimited
      are your friends.





      Comment


      • #4
        Euslaner You haven't told us what form the data come to you in. To me, it looks like a spreadsheet. If so, then importing the data is easy. First ensure that all country names with more than one word have the full name in a single cell (some editing required). Delete the "valid" in top left, and perhaps also the blank rows (though the latter can be done later)

        Then ...

        Code:
        . import excel euslaner.xlsx
        (7 vars, 32 obs)
        
        . list
        
             +----------------------------------------------------------------+
             |   A                        B   C       D      E      F       G |
             |----------------------------------------------------------------|
          1. |   8                  Albania   |    2969   1.32   1.32    1.32 |
          2. |  31               Azerbaijan   |    1800     .8     .8    2.12 |
          3. |  40                  Austria   |    6136   2.73   2.73    4.86 |
          4. |  51                  Armenia   |    3000   1.34   1.34     6.2 |
          5. |  56                  Belgium   |    7358   3.28   3.28    9.47 |
             |----------------------------------------------------------------|
          6. |  70   Bosnia and Herzegovina   |    3236   1.44   1.44   10.92 |
          7. | 100                 Bulgaria   |    5092   2.27   2.27   13.18 |
          8. | 112                  Belarus   |    4048    1.8    1.8   14.99 |
          9. | 124                   Canada   |    2984   1.33   1.33   16.32 |
         10. | 191                  Croatia   |    4015   1.79   1.79   18.11 |
             |----------------------------------------------------------------|
         11. | 196                   Cyprus   |    1000    .45    .45   18.55 |
         12. | 197          Northern Cyprus   |     500    .22    .22   18.78 |
         13. | 203           Czech Republic   |    7649   3.41   3.41   22.18 |
         14. | 208                  Denmark   |    8104   3.61   3.61   25.79 |
         15. | 233                  Estonia   |    4835   2.15   2.15   27.95 |
             |----------------------------------------------------------------|
         16. | 246                  Finland   |    3959   1.76   1.76   29.71 |
         17. | 250                   France   |    7188    3.2    3.2   32.92 |
         18. | 268                  Georgia   |    3694   1.65   1.65   34.56 |
         19. | 276                  Germany   |   11023   4.91   4.91   39.47 |
         20. | 528              Netherlands   |    7199   3.21   3.21   63.21 |
             |----------------------------------------------------------------|
         21. | 578                   Norway   |    4502   2.01   2.01   65.22 |
         22. | 616                   Poland   |    4939    2.2    2.2   67.42 |
         23. | 620                 Portugal   |    4953   2.21   2.21   69.62 |
         24. | 642                  Romania   |    5351   2.38   2.38   72.01 |
         25. | 643                   Russia   |    5829    2.6    2.6   74.61 |
             |----------------------------------------------------------------|
         26. | 688                   Serbia   |    3011   1.34   1.34   75.95 |
         27. | 703                 Slovakia   |    5408   2.41   2.41   78.36 |
         28. | 705                 Slovenia   |    4482      2      2   80.35 |
         29. | 724                    Spain   |    8849   3.94   3.94    84.3 |
         30. | 752                   Sweden   |    5397    2.4    2.4    86.7 |
             |----------------------------------------------------------------|
         31. | 756              Switzerland   |    4445   1.98   1.98   88.68 |
         32. | 792                   Turkey   |    3590    1.6    1.6   90.28 |
             +----------------------------------------------------------------+
        Next (i) -drop C-; and (ii) -rename- each of the other column names to a variable name that makes sense to you.

        If the data are in some other format (SPSS or whatever), there should be a way of writing out as a plain text file (followed by Carlo Lazzaro 's solution based on -input-) or CSV or other spreadsheet format.

        Comment


        • #5
          Nick Cox and Stephen Jenkins are obviously right and provided much better solutions.
          In my example I went back to those days when even -input-ting a single observation in Stata was an incredible success!
          Kind regards,
          Carlo
          (Stata 19.0)

          Comment


          • #6
            Euslaner You started a new thread on a different topic, which is fine. https://www.statalist.org/forums/for...g-observations

            If you are done here, please close the thread appropriately, e.g. by explaining the resolution.

            Comment

            Working...
            X