Announcement

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

  • Replace command with multiple variables

    Hello everyone,

    I would like to ask you for help regarding a typology for parenting styles with the replace command.
    I want to differentiate between four styles via the combination of four variables and the replace command.

    However, the replace code doesn't work the error says "invalid replace".
    This my code:

    gen erziehungsstile = 1
    replace erziehungsstile = 2 if warmth_pacs<3.66 | negcomm_pacs>3 ///
    | inconsist_pacs<2.75 ///
    | monitor_pacs>3.5 ///
    replace erziehungsstile = 3 if warmth_pacs<3.66 | negcomm_pacs>3 ///
    | inconsist_pacs<2.75 ///
    | monitor_pacs<3.5 ///
    replace erziehungsstile = 4 if warmth_pacs>3.66 | negcomm_pacs<3 ///
    | inconsist_pacs>2.75 ///
    | monitor_pacs<3.5


    Do you have any ideas what could be an alternative to combine these four variables into one?

    Thanks in advance!

  • #2
    You are using /// incorrectly. After the separate -gen- command, you have given Stata what looks, to it, like one long, uninterrupted command. And the term -replace- occurs not just at the beginning, but also twice in the midst of this long command. Stata can't make any sense of that. Edit out the surplus ///'s and retain only those that fall within separate lines of a single command. Thus:
    Code:
    gen erziehungsstile = 1
    replace erziehungsstile = 2 if warmth_pacs<3.66 | negcomm_pacs>3 ///
    | inconsist_pacs<2.75 ///
    | monitor_pacs>3.5
    
    replace erziehungsstile = 3 if warmth_pacs<3.66 | negcomm_pacs>3 ///
    | inconsist_pacs<2.75 ///
    | monitor_pacs<3.5
    
    replace erziehungsstile = 4 if warmth_pacs>3.66 | negcomm_pacs<3 ///
    | inconsist_pacs>2.75 ///
    | monitor_pacs<3.5 
    Note: The blank lines I have placed between the three -replace- commands are not needed, but they make the code more readable to humans, and they also help draw your attention to the places immediately preceding them where an inappropriate /// was found in the original code.

    Comment

    Working...
    X