Announcement

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

  • How to find numerical variables are in the data?

    Hello,

    First of all, I apologize if I am posting the question in wrong part of the forum.

    I have just started learning Stata and I've a few questions -

    What is the command to find out how many numerical variables are in the data?

    How to summarize their basic descriptive statistics in a table? Command?


    Any help with these would be highly appreciated!

    Thank you.
    Last edited by John Klar; 20 Sep 2018, 22:43. Reason: Stata, Command, Descriptive Statistics, Numerical Variable

  • #2
    A couple of commands that you will want to learn about for this sort of activity are codebook and inspect. To learn more about them, at the command line in Stata, type
    Code:
    help codebook
    and
    Code:
    help inspect
    To see a quick example in action, type this
    Code:
    sysuse auto
    codebook

    Comment


    • #3
      Also, to your first question specifically, you can look at the commands describe and ds, the latter with its has(type numeric) option.

      Comment


      • #4
        Originally posted by Joseph Coveney View Post
        Also, to your first question specifically, you can look at the commands describe and ds, the latter with its has(type numeric) option.
        Dear Joseph, thank you so much. These helped a lot but I am not able to understand what do you mean by has (type numeric)

        In my data set Price is numeric variable so does it mean I have to type has (price)? I tried but it is giving me an error.

        Comment


        • #5
          It's an option to the command. For a quick example of how the command can be used, type the following at the command line
          Code:
          sysuse auto
          ds , has(type numeric)
          return list
          summarize `r(varlist)'
          For more detailed information, type the following
          Code:
          help ds

          Comment


          • #6
            Originally posted by Joseph Coveney View Post
            It's an option to the command. For a quick example of how the command can be used, type the following at the command line
            Code:
            sysuse auto
            ds , has(type numeric)
            return list
            summarize `r(varlist)'
            For more detailed information, type the following
            Code:
            help ds
            I got it now. Thank you so much once again. Much appreciated your help!

            Comment


            • #7
              ds is an official command, although as documented in the manual it incorporates contributions from the community.

              findname (Stata Journal) is intended by its author to add features to ds and (personal judgement here) to improve on the syntax.


              SJ-15-2 dm0048_3 . . . . . . . . . . . . . . . . Software update for findname
              (help findname if installed) . . . . . . . . . . . . . . . N. J. Cox
              Q2/15 SJ 15(2):605--606
              updated to be able to find strL variables

              SJ-12-1 dm0048_2 . . . . . . . . . . . . . . . . Software update for findname
              (help findname if installed) . . . . . . . . . . . . . . . N. J. Cox
              Q1/12 SJ 12(1):167
              correction for handling embedded double quote characters

              SJ-10-4 dm0048_1 . . . . . . . . . . . . . . . . Software update for findname
              (help findname if installed) . . . . . . . . . . . . . . . N. J. Cox
              Q4/10 SJ 10(4):691
              update for not option

              SJ-10-2 dm0048 . . . . . . . . . . . . . . Speaking Stata: Finding variables
              (help findname if installed) . . . . . . . . . . . . . . . N. J. Cox
              Q2/10 SJ 10(2):281--296
              produces a list of variable names showing which variables
              have specific properties, such as being of string type, or
              having value labels attached, or having a date format


              Here for finding which variables are numeric findname doesn't add anything but the syntax may seem a little less odd and an extra feature is the ability to push the results into a local macro:

              Code:
              . sysuse auto, clear
              (1978 Automobile Data)
              
              . findname, type(numeric) local(numeric)
              price         headroom      length        gear_ratio
              mpg           trunk         turn          foreign
              rep78         weight        displacement
              
              . su `numeric'
              
                  Variable |        Obs        Mean    Std. Dev.       Min        Max
              -------------+---------------------------------------------------------
                     price |         74    6165.257    2949.496       3291      15906
                       mpg |         74     21.2973    5.785503         12         41
                     rep78 |         69    3.405797    .9899323          1          5
                  headroom |         74    2.993243    .8459948        1.5          5
                     trunk |         74    13.75676    4.277404          5         23
              -------------+---------------------------------------------------------
                    weight |         74    3019.459    777.1936       1760       4840
                    length |         74    187.9324    22.26634        142        233
                      turn |         74    39.64865    4.399354         31         51
              displacement |         74    197.2973    91.83722         79        425
                gear_ratio |         74    3.014865    .4562871       2.19       3.89
              -------------+---------------------------------------------------------
                   foreign |         74    .2972973    .4601885          0          1
              The original article is long since in front of the paywall: https://www.stata-journal.com/sjpdf....iclenum=dm0048 but if you are interested in the software download the most recent version.

              A further version of findname is likely to be released with Stata Journal 18(4) or 19(1) with small additions to do with value labels. But already findname can do a lot that ds can't, e.g. find all indicator variables with values 0 or 1 or missing or find all variables that are constant.

              Comment

              Working...
              X