Announcement

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

  • Wrapping lines in a do file within a text field

    I would like to split some of the variable labels in my do file across two lines so that all variable names align with a long list in my do file. I have tried a few strategies below, but all receive an invalid syntax error where the variable names wrap to the second line.

    Strategy 1:
    Code:
    label variable owner                        "Owner (Agency & Contact if External - Program or" ///
                                                + "HART if Internal)"
    label variable developer                    "Developer (Agency if external - Person if internal" ///
                                                + "to DRHD)"
    Strategy 2:
    Code:
      label variable owner                        "Owner (Agency & Contact if External - Program or" /*
                                                */ + "HART if Internal)"
    label variable developer                    "Developer (Agency if external - Person if internal" /*
                                                */ + "to DRHD)"
    Strategy 3
    Code:
     #delimit ;
     label variable owner                        "Owner (Agency & Contact if External - Program or" /*
                                                */ + "HART if Internal)";
    label variable developer                    "Developer (Agency if external - Person if internal" /*
                                                */ + "to DRHD)";
    #delimit cr
    Any suggestions are much appreciated.

  • #2
    Originally posted by Shannon Meadows View Post
    #delimit ;
    label variable owner "Owner (Agency & Contact if External - Program or" /*
    */ + "HART if Internal)";
    label variable developer "Developer (Agency if external - Person if internal" /*
    */ + "to DRHD)";
    #delimit cr
    Why are you adding comments?

    Code:
    #delimit ;
    label variable owner "Owner (Agency & Contact if External - Program or
        HART if Internal)";
    
    label variable developer "Developer (Agency if external - Person if internal
        to DRHD)";
    #delimit cr

    Comment


    • #3
      I needed to add longer variable labels to match another data asset. When I tried this code, the variable label did not include the second line for each "owner" and "developer" variables. As well, the text inside the brackets appear as white, instead of appearing orange like the other variable labels.

      Code:
      #delimit ;
      label variable owner                        "Owner (Agency & Contact if External - Program or HART
                                                  if Internal)";
      label variable developer                    "Developer (Agency if external - Person if internal
                                                  to DRHD)";
      #delimit cr

      Comment


      • #4
        If your question is whether you can split a variable label over multiple lines, then the answer is no. The code that I show just allows you to do this within a do-file, but the generated label is not split over 2 lines or more. Furthermore, there are restrictions to the length of a variable label. If you check out

        Code:
        help limits
        you have:

        label
        length of dataset label (characters) 80 80
        length of variable label (characters) 80 80
        length of value label string
        (bytes) 32,000 32,000
        length of name of value label
        (characters) 32 32
        # of codings within one
        value label 65,536 65,536
        I do not know much about or pay attention to color coding within do-files. Here is a test of my code in #2 using the auto dataset.

        Code:
        sysuse auto, clear
           #delimit ;
        label variable mpg "Owner (Agency & Contact if External - Program or
            HART if Internal)";
        
        label variable turn "Developer (Agency if external - Person if internal
            to DRHD)";
        #delimit cr
        
        describe
        Res.:

        Code:
        . describe
        
        
         Observations:            74                  1978 automobile data
            Variables:            12                  13 Apr 2022 17:45
                                                      (_dta has notes)
        -------------------------------------------------------------------------------------------------------------------------------------------------
        Variable      Storage   Display    Value
            name         type    format    label      Variable label
        -------------------------------------------------------------------------------------------------------------------------------------------------
        make            str18   %-18s                 Make and model
        price           int     %8.0gc                Price
        mpg             int     %8.0g                 Owner (Agency & Contact if External - Program or HART if Internal)
        rep78           int     %8.0g                 Repair record 1978
        headroom        float   %6.1f                 Headroom (in.)
        trunk           int     %8.0g                 Trunk space (cu. ft.)
        weight          int     %8.0gc                Weight (lbs.)
        length          int     %8.0g                 Length (in.)
        turn            int     %8.0g                 Developer (Agency if external - Person if internal to DRHD)
        displacement    int     %8.0g                 Displacement (cu. in.)
        gear_ratio      float   %6.2f                 Gear ratio
        foreign         byte    %8.0g      origin     Car origin
        -------------------------------------------------------------------------------------------------------------------------------------------------
        Sorted by: foreign
             Note: Dataset has changed since last saved.
        
        .
        end of do-file
        Last edited by Andrew Musau; 03 Sep 2024, 11:53.

        Comment

        Working...
        X