Announcement

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

  • How to get -stack- to loop through my variable list and keep therm all in one file?

    I have a number of variables with the a time subscript (0, 6 ,8, and 10). I wish to create a stacked variables from these into, for example, v0_6, v0_8, v0_10 using the command
    HTML Code:
    -stack-
    . I wish to retain the original variables. The following code stops looping after the first variable. Here is the code and the warning message.

    HTML Code:
      foreach v in SkinTodayChild SkinTodayParent SCORADExtTotal SCORADIntTotal SCORADSubPruritus SCORADSubSleepLoss ///
      SCORADSubTotal SCORADFinalTotal CDLQI_Score CDLQIP_Score IDQOL_Score FDLQI_Score  ///
      POEMP_Score POEMC_Score  DFI_Score InvGlobalAssess EczFlaresNumber AsthmaBTSStep {
      stack `v'0 `v'6 `v'0 `v'8 `v'0 `v'10, into(`v'0_6 `v'0_8 `v'0_10 )  wide
      }
    The warning message is:

    HTML Code:
    Warning:  data in memory will be lost.
             Press any key to continue, Ctrl-Break to abort.
    variable SkinTodayParent0 not found
    I would be grateful for any advice on how to modify my code so that the code loops through all variables and keeps everything in one file. many thanks.

  • #2
    You're opening up HTML code boxes using the <> tag in the editor. Use the # tag to open code boxes.

    The loop here is fallacious. Once you stack once, the dataset structure is completely changed and any further stacks could at most be in terms in the variables of the stacked dataset. Alternatively, doing a set of stacks is not illegal, but you'd need to read in the original dataset each time. It seems unlikely that is what you really want; you'd just be mapping to several new datasets.

    You should back up and explain with an example the data structure you have and why you think you need a new structure. See FAQ Advice #12. At a guess, you need a single reshape long. No loop is needed, or indeed helpful.

    Comment

    Working...
    X