Announcement

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

  • Making "dataex" command work to export lines of code to statalist

    Hello,

    I can get dataex to work when all I need to do is get state to make a list of values, but I can't make dataex work when I'm trying to export lines of code.

    If I put dataex in the same line as my code, I'm told 'variable not found'.
    If I put dataex in a line above my code, I'm told 'input statement exceeds linesize limit. Try specifying fewer variables'. See screenshot below:
    Click image for larger version

Name:	Screen Shot 2019-03-20 at 10.52.57.png
Views:	1
Size:	26.6 KB
ID:	1489091




    This is the code I would like to export using dataex:
    gen occsoc_noX = subinstr(occsoc, "X", "0", .)
    destring occsoc_noX, gen (occsoc_num)

    drop occsoc_noX
    gen occsoc_noblanks = occsoc
    replace occsoc_noblanks = strtrim(occsoc_noblanks)
    gen occsoc_noX = subinstr(occsoc_noblanks, "X", "0", .)
    destring occsoc_noX, gen (occsoc_num)
    What should I do? Have I perhaps misunderstood the function of the command 'dataex'?

    Thanks for your time and consideration.

    Rosa

  • #2
    Yes, this is a misunderstanding of dataex. dataex makes it easier to give data examples that people can use by showing code within CODE delimiters that produces that data as a dataset.

    To show code within CODE delimiters, just use the editing keys directly as explained at 12.3 in
    https://www.statalist.org/forums/help#stata

    Code:
    gen occsoc_noX = subinstr(occsoc, "X", "0", .)
    destring occsoc_noX, gen (occsoc_num)
    
    drop occsoc_noX
    gen occsoc_noblanks = occsoc
    replace occsoc_noblanks = strtrim(occsoc_noblanks)
    gen occsoc_noX = subinstr(occsoc_noblanks, "X", "0", .)
    destring occsoc_noX, gen (occsoc_num)
    Last edited by Nick Cox; 20 Mar 2019, 04:10.

    Comment


    • #3
      This explains it, thanks a lot Nick.

      Comment

      Working...
      X