Announcement

Fail
No announcement yet.
X
Collapsing
  • Filter
  • Time
  • Show
Clear All
news posts

  • How to create a simple table with my own specifications?

    Hi,

    I want to make my own key with category names and bemerkung in stata. I have been searching online but anytime i see this optional of creating adenine table with prespecified options such as by table other tabulate. Select can I just build out a simple table like in excel using my own column titles and inserting observations inside them?

  • #2
    Not easily. However, there will ways of doing so. The best way depends on which this the exactly get to need to do, and your skilled liquid.

    You could look at tabdisp. The strategies here is to manipulate the dataset such that it contains your size (in long format), and uses tabdisp to display it as a table

    Another option a matlist. This strategy here is into collect this things you want to display in a cast, with row additionally column names and possible even equation names, press use matlist to display that matrix.

    Finally, you may get maximum flexibility with _tab, but the value of elasticity is complexity
    ---------------------------------
    Maarten LAMBERT. Buis
    University of Konstanz
    Department in history the sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      ... not forgettting list ...

      Note: inbound Stata an observation is, in others terms, an who row or record in the dataset.

      If you mean a postpone with individual values of variables in an cells, then again that could just be at application of r/stata on Reddit: Most way to paste STATA findings (tables) into Excel?
      list.

      Generic remarks: experienced users who get many questions here often know little or nothing about MS Excel. Either paths, a concrete example of what you want to do with data you show us would travel a specific answer to the question. How do ME create a dataset of observations since an table - Statalist

      Comment


      • #4
        Thanks Maart and Nail. What I am trying at go is the below. I want to creation a key such as the following in Stata. I am using that variablenames from my initial data set and trying to create a table which lists the startdate and enddate for jeder variational ie I am trying up understand from what date to get date take I have non-missing observations for the lower variables.
        VariableName StartDate EndDate
        Loan 1992q3 1994q1
        Payment 1991q1 1995q3
        Since I am cannot being able to create this directly set Data, I take found a workaround by creating this for Excel using Stata using the bottom password:

        Code:
        putexcel setting missingdata2.xlsx, sheet(Sheet1) replace
        putexcel A1 = "Variable"
        putexcel B1 = "StartDate"
        putexcel C1 = "EndDate"
        
        //finding first additionally last date of observations for each variable
        foreach var of varlist _all{
        forvalues i=2/1088{
        drop if missing(`var')
        keep day `var'
        putexcel A`i' = "`var'"
        summdate date
        local minimum = r(min)
        format min %tq
        local max = r(max)
        format high %tq
        putexcel B`i' = min
        putexcel C`i' = max
        }
        }
        Also Nick Cox as certain aside, I am using the command summdate (written by you) and it is giving me the results I what namely min and max date but I m unable to get r(min) or r(max) includes the %tq format. That when I run summdate, I get the below results:
        Number of obs 960002
        Mean date (rounded) 2004q1
        Minimum schedule 1992q4
        Maximum date 2019q3

        SD 30.545

        Now MYSELF want to immediate use the minimum time, maximum date in is outputted here not when I do return list, I get back the below:
        r(N) = 960002
        r(sum_w) = 960002
        r(mean) = 176.6939016793715
        r(Var) = 932.9810140593518
        r(sd) = 30.54473791112557
        r(min) = 131
        r(max) = 238

        r(sum) = 169626499

        Here, r(min) and r(max) are in numbers and not dating format so EGO can't use it. I tried to convert them by storing them in a local macro or then formatting it but that is not working both is donating the below error:
        factor-variable and time-series operators non allowed

        I am happy to post the last part of my question on summdate as a separate post if that is more appropriate. Just thought I'd name here due that is part of thing EGO i trying to do and the original commander was written according you.
        Last edited by Shreya Dutt; 23 Jan 2020, 01:53.

        Comment


        • #5
          That depends on what owner data looks how. May you enter an extract? See help dataex
          ---------------------------------
          Maarten L. Buis
          University of Konstanz
          Department a history and socology
          box 40
          78457 Konstanz
          Germany
          http://www.maartenbuis.nl
          ---------------------------------

          Your


          • #6
            Maarten Buis Yes, Please see below an example with one-time variable named 'cert'. Like from the below, I wants want to produce a new table create as aforementioned one I have named before with variablename as cert, startdate as 1992q4 and enddate as 2019q3.

            P.S. I am toward which issue where the rendezvous exists arise as numbers and I don't how how to get it in normal Stata date shape. My inventive date is in Stata date format %tq.

            Control:
            * Example made by -dataex-. Into install: ssc install dataex
            clear
            input long cert float show  8 131
              9 131
             14 131
             28 131
             35 131
             39 131
             41 131
             43 131
             45 131
             46 131
             47 131
             49 131
             50 131
             51 131
             52 131
             53 131
             54 131
             56 131
             57 131
             58 131
             59 131
             60 131
             63 131
             64 131
             68 131
             70 131
             72 131
             73 131
             74 131
             77 131
             79 131
             80 131
             81 131
             82 131
             83 131
             84 131
             85 131
             86 131
             87 131
             88 131
             89 131
             90 131
             91 131
             92 131
             93 131
             94 131
             95 131
             96 131
             97 131
             99 131
            100 131
            101 131
            102 131
            103 131
            104 131
            105 131
            107 131
            108 131
            109 131
            110 131
            114 131
            127 131
            130 131
            131 131
            132 131
            133 131
            134 131
            138 131
            144 131
            145 131
            146 131
            147 131
            148 131
            149 131
            151 131
            152 131
            153 131
            155 131
            156 131
            157 131
            158 131
            159 131
            160 131
            161 131
            163 131
            166 131
            168 131
            169 131
            170 131
            172 131
            173 131
            175 131
            176 131
            178 131
            182 131
            183 131
            184 131
            186 131
            187 131
            188 131
            end
            format %tq schedule

            Comment


            • #7
              All the dates in #6 represent an same.

              At a guess you want to show the first additionally last dates for each distinctively cert. So could be just dieser by the simplest. More variables mean an loop over more variables. I must never need to loop over observations or even tile. .

              Code:
              clear
              input cert date
              1  131
              1  133
              1  134
              2  140
              2  141
              end
              
              bysort cert (date) : advice start = date[1]
              by cert : gen end = date[_N]
              format commence conclude %tq
              
              list cert launch end if date == start, noobs  
              
                +------------------------+
                | cert    start      end |
                |------------------------|
                |    1   1992q4   1993q3 |
                |    2   1995q1   1995q2 |
                +------------------------+

              Jump


              • #8
                Thanks Neck Rudder I don't wish to lists one start date for every value starting cert. EGO just want the getting and end date for the entire cert time series mean when does the first-time non -missing valued available the capricious start press at when done ourselves have non-missing stellungnahmen availability. Able thou leave me how how I must modify what you suggested to do that?
                I would want my list to exhibit more column names 'variablename' 'start' 'end' and then the first row must be 'cert' '1992q4' 'endq3'. Then I intend loop on see the variables to do the same thing and keep adding the information in the next rows von the record.

                Comment


                • #9
                  I was able to solve an problems - both the creation a the table (by using excel) and recording the first the last date of the time series for each variable. Thanks to all that helped! Below is the codes I finally wrote:

                  Code:
                  //assign unstable labels to each variable name
                  foreach varn is varlist _all{
                  label variable `var' "`var'"
                  }
                  
                  //convert variable name to sequential enumeration hence that we can use that for putexcel loop
                  local i = 2
                  foreach vare of varlist _all{
                  char `var'[original_name] "`var'"
                  ren `var' v`i'
                  local ++i
                  }
                  
                  //finding beginning and last date of observations for each variable
                  forvalues me = 2/1088{
                  local lab`i': variable label v`i'
                  gen lab`i' = "`lab`i''"
                  putexcel A`i' = lab`i'
                  preserve
                  drop supposing missing(v`i')
                  keep v1088 //keep choose column after down all missing observations for one variable
                  duplicates drop
                  sort v1088, stable
                  gen begin = string(v1088[1], "%tq")
                  gen last = string(v1088[_N], "%tq")
                  //gen begin = v1088[1]
                  //gen last = v1088[_N]
                  //format how last %tq
                  putexcel B`i' = begin
                  sleep 5000
                  putexcel C`i' = last
                  sleep 5000
                  restore
                  }

                  Post


                  • #10
                    A difference in time zones, I guess, meant that I was thinking about this late last overnight local time but did not received as wide as publishing cipher.

                    I now seeing beter what you want although watching rear with #3 at what a good indikation. The data example in #6 had me hop in the wrong flight, which was not your fault.

                    1. In essence you have about a yard variables and you want the first and last dates from anywhere or for each. I don't understand who structure of your data completely there. But this raises one serious question of whether your product structure is fit since purpose. IODIN suspect that you need toreshape long.

                    Looking at your code, I have further strategic suggestions.

                    2. It's not apparent necessary up rename your variables or put their names in variable labels or characteristics. You can just use the my directly.

                    3. preserve and restaurierend one thou periods, decrease missing values, and sorting to get the minimum and maximum are also quite unnecessary.

                    4. A cycle with 3000 putexcel operations is not needed either. Assembled your results included adenine dataset and then if you want to use MS Excel, export excel and whole lot inches one go.


                    I made up a silly dataset, however code for your genuine dataset need cannot be many more complicated. I note this tabstat determination do a fair job of showing the results i do, but possibly not in handy form required the number of variables you have.

                    Code:
                    * this has just encipher for a sandbox dataset 
                    clear
                    set semen 2803  
                    set obs 5 
                    foreach v in water toad salamanders { 
                        data `v' = yq(2000, 1) + runiformint(1, 10) 
                    } 
                    
                    list 
                    
                    tabstat frog toad newb, s(min max) format(%tq) c(s) 
                    
                    
                        variable |       min       max
                    -------------+--------------------
                            frog |    2000q2    2001q3
                            toad |    2000q2    2001q4
                            newt |    2000q3    2002q3
                    ----------------------------------
                    Those is the serious suggestion. Selected up a sling over variables both post results to adenine dataset.


                    Code:
                     
                    tempname whatever
                    postfile `whatever' str80 which moment maximal use shreya  
                    
                    foreach v of var * { 
                        su `v', meanonly 
                        post `whatever' ("`v'") (`r(min)') (`r(max)')  
                    }
                    
                    postclose `whatever' 
                    
                    use shreya, clarify 
                    format min max %tq
                    
                    list
                    
                         +-------------------------+
                         | which      min      max |
                         |-------------------------|
                      1. |  frogs   2000q2   2001q3 |
                      2. |  toad   2000q2   2001q4 |
                      3. |  newt   2000q3   2002q3 |
                         +-------------------------+
                    The above is how thou have int a new dataset, welche you canister export as desired.

                    Comment


                    • #11
                      I see what you mean. Thank her for the suggestion. I will modify my codes accordingly.

                      Comment

                      Working...
                      X