Announcement

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

  • How to save descriptive results in Stata data (.dta) format?

    Dear user, I used this code:
    sysuse auto.dta
    mean price, over ( foreign )

    My results are:
    --------------------------------------------------------------
    -
    Over | Mean Std. Err. [95% Conf. Interval]
    -------------+------------------------------------------------
    price |
    Domestic | 6072.423 429.4911 5216.449 6928.398
    Foreign | 6384.682 558.9942 5270.608 7498.756
    -------------------------------------------------------------

    Now i want to save these mean, standard deviation and confidence interval in Stata data format (.dta). How to do it? if there is code please share.

  • #2
    You might want to take a look at here.

    Comment


    • #3
      Code:
      . sysuse auto
      (1978 Automobile Data)
      
      . statsby , by(foreign) : ci means price
      (running ci on estimation sample)
      
            command:  ci means price
                  N:  r(N)
               mean:  r(mean)
                 se:  r(se)
                 lb:  r(lb)
                 ub:  r(ub)
              level:  r(level)
                 by:  foreign
      
      Statsby groups
      ----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5 
      ..
      
      . list 
      
           +-------------------------------------------------------------------+
           |  foreign    N       mean         se         lb         ub   level |
           |-------------------------------------------------------------------|
        1. | Domestic   52   6072.423   429.4911   5210.184   6934.663      95 |
        2. |  Foreign   22   6384.682   558.9942    5222.19   7547.174      95 |
           +-------------------------------------------------------------------+

      Comment


      • #4
        Dear Nick, The code you have provided might need to rearrange. I used the code:
        statsby , by( foreign ) : means price

        Please suggest me the in the next query:
        I want to estimate means if rep78==3 and rep78==2. Then, i want to save the both Stata files into one Stata file. After that i need to plot means of both rep78==3 and rep78==2 across the foreign. Please suggest me how to do?

        statsby , by( foreign ) : means price if rep78==3
        statsby , by( foreign ) : means price if rep78==2

        Comment


        • #5
          My code seems to save what you want so I am not clear why you want to "rearrange" it.

          The extra twist of working with further subsets can be met with

          Code:
          sysuse auto, clear 
          statsby if inlist(rep78, 2, 3), by(foreign rep78) : ci means price

          Comment


          • #6
            Hi Biswa. I can't find the old thread right now, but the use of -mean- to get the CIs for two or more groups has come up before, because -mean- uses one critical value of t for all of the groups, and it is the critical t with df = Ntotal - 1. Run the following code to see that this happens for your example.

            Code:
            clear *
            sysuse auto.dta
            ttest price, by(foreign)
            mean price, over ( foreign )
            matrix list r(table)
            Compare the CIs from the -ttest- output to those from -mean-. And notice that for both foreign and domestic vehicles, -mean- uses the same critical t-value with df = 73.

            Code:
            r(table)[9,2]
                        price:     price:
                     Domestic    Foreign
                 b  6072.4231  6384.6818
                se  429.49109  558.99417
                 t  14.138647  11.421732
            pvalue  1.353e-22  6.520e-18
                ll  5216.4486   5270.608
                ul  6928.3976  7498.7556
                df         73         73
              crit  1.9929971  1.9929971
             eform          0          0
            Unless this is really how you want to compute the CIs (which I doubt), I suggest using another method, such as -statsby-, as suggested by Nick in #3 and #5.

            HTH.
            --
            Bruce Weaver
            Email: [email protected]
            Version: Stata/MP 18.5 (Windows)

            Comment

            Working...
            X